fork(2) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Circles
  9. {
  10. class Program
  11. {
  12. /// <summary>
  13. /// Структура круга
  14. /// </summary>
  15. struct t_circle {
  16. public int x, y, d;
  17. public t_circle(int x, int y, int d)
  18. {
  19. this.x = x;
  20. this.y = y;
  21. this.d = d;
  22. }
  23. }
  24. static List<t_circle> l_circles = new List<t_circle>();
  25.  
  26. /// <summary>
  27. /// Рекурсивно добавляет структуры кругов в массив, пока n>0
  28. /// </summary>
  29. static void add_circle( int x, int y, int dia, int n)
  30. {
  31. if (n>0)
  32. {
  33. //Console.WriteLine($"{x}, {y}, {dia}, {n}");
  34. t_circle t = new t_circle(x, y, dia);
  35. l_circles.Add(t);
  36.  
  37. add_circle(x - dia / 2, y, dia / 2, n - 1);
  38. add_circle(x + dia / 2, y, dia / 2, n - 1);
  39. add_circle(x, y - dia / 2, dia / 2, n - 1);
  40. add_circle(x, y + dia / 2, dia / 2, n - 1);
  41. }
  42. }
  43.  
  44. static void Main(string[] args)
  45. {
  46. Console.Write("Enter depth of circles [1..6] : ");
  47. string val = Console.ReadLine();
  48. try
  49. {
  50. int n = Convert.ToInt32(val);
  51.  
  52. if (n<1 || n>6)
  53. {
  54. Console.WriteLine("invalid input!");
  55. } else
  56. {
  57. int dia = Convert.ToInt32(20 * Math.Pow(2, n));
  58. int w = dia * 2;
  59.  
  60. add_circle(w/2, w/2, dia, n);
  61.  
  62. Bitmap bmp = new Bitmap(w, w);
  63. using (Graphics graph = Graphics.FromImage(bmp))
  64. {
  65. Rectangle ImageSize = new Rectangle(0, 0, w, w);
  66. graph.FillRectangle(Brushes.White, ImageSize);
  67.  
  68. Pen pen = new Pen(Color.Black, 1);
  69. foreach (var t in l_circles)
  70. graph.DrawEllipse(pen, t.x - t.d / 2, t.y - t.d / 2, t.d, t.d);
  71. }
  72. string filePath = AppDomain.CurrentDomain.BaseDirectory + $"out_{n}.bmp";
  73. bmp.Save(filePath);
  74. Console.WriteLine($"Image saved to \"{filePath}\"");
  75. }
  76. }
  77. catch (Exception e)
  78. {
  79. Console.WriteLine(e.Message);
  80. throw;
  81. }
  82.  
  83. }
  84. }
  85. }
  86.  
Success #stdin #stdout 0.02s 16544KB
stdin
Standard input is empty
stdout
Enter depth of circles [1..6] : invalid input!