Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace WindowsFormsApplication1
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. }
  18.  
  19. private void button1_Click(object sender, EventArgs e)
  20. {
  21. m = 1;
  22. timer1.Start();
  23. }
  24. void patrat(int n, int x, int y, int l)
  25. {
  26. int l2 = l / 2;
  27. int l4 = l / 4;
  28. int l3 = l2 + l4;
  29. if (n > 1)
  30. {
  31. patrat(n - 1, x - l4, y - l4, l2);
  32. patrat(n - 1, x - l4, y + l3, l2);
  33. patrat(n - 1, x + l3, y - l4, l2);
  34. patrat(n - 1, x + l3, y + l3, l2);
  35. }
  36. Graphics graph = this.CreateGraphics();
  37. Pen penc;
  38. if (n % 2 == 0) penc = new Pen(Color.Red);
  39. else penc = new Pen(Color.BlueViolet);
  40. Point[] p = new Point[4];
  41. p[0].X = x; p[0].Y = y;
  42. p[1].X = x; p[1].Y = y + l;
  43. p[2].X = x + l; p[2].Y = y + l;
  44. p[3].X = x + l; p[3].Y = y;
  45. graph.DrawPolygon(penc, p);
  46. }
  47.  
  48. private void timer1_Tick(object sender, EventArgs e)
  49. {
  50. if (m <= Convert.ToInt32(textBox1.Text))
  51. {
  52. int x = 300, y = 300, l = 150;
  53. patrat(m, x, y, l);
  54. m = m + 1;
  55. }
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement