Advertisement
nastiia_firefly

The Sierpinski Carpet

Nov 13th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. //---------------------------------------------------------------------------
  2.  
  3. #include <vcl.h>
  4. #pragma hdrstop
  5. #include <math.h>
  6.  
  7. #include "Unit1.h"
  8. //---------------------------------------------------------------------------
  9. #pragma package(smart_init)
  10. #pragma resource "*.dfm"
  11. TForm1 *Form1;
  12. //---------------------------------------------------------------------------
  13. __fastcall TForm1::TForm1(TComponent* Owner)
  14. : TForm(Owner)
  15. {
  16. }
  17. //---------------------------------------------------------------------------
  18.  
  19. void Serp(double x0, double y0,double x1, double y1,double n)
  20. {
  21.  
  22.  
  23.  
  24. if(n>0)
  25. {
  26. Form1->Image1->Canvas->Brush->Color = clPurple;
  27. Form1->Image1->Canvas->FillRect(Rect(x0 + (x1-x0)/3, y0 + (y1-y0)/3, x0 + 2*(x1-x0)/3, y0+2*(y1-y0)/3 ));
  28.  
  29. Form1->Image1->Canvas->Brush->Color = clWhite;
  30.  
  31. Serp(x0 , y0 , x0 + (x1-x0)/3, y0+ (y1-y0)/3, n-1 );
  32. Serp(x0 + (x1-x0)/3, y0 , x0 + 2*(x1-x0)/3, y0+ (y1-y0)/3, n-1 );
  33. Serp(x0 + 2*(x1-x0)/3, y0 , x0 + 3*(x1-x0)/3, y0+ (y1-y0)/3, n-1 );
  34.  
  35. Serp(x0 , y0 + (y1-y0)/3 , x0 + (x1-x0)/3 , y0+2*(y1-y0)/3, n-1 );
  36. Serp(x0 +2*(x1-x0)/3 , y0 + (y1-y0)/3 , x0 + 3*(x1-x0)/3, y0+2*(y1-y0)/3, n-1 );
  37.  
  38. Serp(x0 , y0+2*(y1-y0)/3 , x0 + (x1-x0)/3, y0+ 3*(y1-y0)/3, n-1 );
  39. Serp(x0 + (x1-x0)/3, y0+2*(y1-y0)/3 , x0 + 2*(x1-x0)/3, y0+ 3*(y1-y0)/3, n-1 );
  40. Serp(x0 + 2*(x1-x0)/3, y0+2*(y1-y0)/3 , x0 + 3*(x1-x0)/3, y0+ 3*(y1-y0)/3, n-1 );
  41. }
  42.  
  43. }
  44.  
  45.  
  46.  
  47. void __fastcall TForm1::Button1Click(TObject *Sender)
  48. {
  49. double n=0;
  50.  
  51. n=StrToFloat(Edit1->Text);
  52.  
  53. double x0=0,y0=0,
  54. x1=550,y1=550;
  55.  
  56.  
  57. Form1->Image1->Canvas->Rectangle(x0,y0,x1,y1);
  58. Serp(x0,y0,x1,y1,n);
  59.  
  60.  
  61. }
  62. //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement