Advertisement
MrsMcLead

Sierpinski

Mar 11th, 2016
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. int x1, y1, x2, y2, x3, y3;//set dots
  2. int randX, randY;//random dot
  3. int xLast, yLast;
  4.  
  5. void setup()
  6. {
  7.   size(800, 800);
  8.   background(#F5ECCF);
  9.   noStroke();
  10.   x1 = 250;
  11.   y1 = 250;
  12.   x2 = 250;
  13.   y2 = 550;
  14.   x3 = 550;
  15.   y3 = 50;
  16.   randX = (int)random(100)+350;
  17.   randY = (int)random(100)+350;
  18.   xLast = randX;
  19.   yLast = randY;
  20.  
  21.   //color 1
  22.   fill(#F26530);
  23.   ellipse(x1, y1, 5, 5);
  24.  
  25.   //color 2
  26.   fill(#71A235);
  27.   ellipse(x2, y2, 5, 5);
  28.  
  29.   //color 3
  30.   fill(#27BDB2);
  31.   ellipse(x3, y3, 5, 5);
  32.  
  33.   fill(0);
  34.   ellipse(randX, randY, 5, 5);
  35.   frameRate(700);
  36. }
  37.  
  38. void draw()
  39. {
  40.   int roondy = (int)random(4);
  41.   if (roondy == 1) //color 1
  42.   {
  43.     fill(#F26530);
  44.     xLast = (x1 + xLast)/2;
  45.     yLast = (y1+yLast)/2;
  46.     ellipse(xLast, yLast, 5, 5);
  47.   } else if (roondy == 2) //color 2
  48.   {
  49.     fill(#71A235);
  50.     xLast = (x2 + xLast)/2;
  51.     yLast = (y2+yLast)/2;
  52.     ellipse(xLast, yLast, 5, 5);
  53.   } else
  54.   {
  55.     fill(#27BDB2);
  56.     xLast = (x3 + xLast)/2;
  57.     yLast = (y3+yLast)/2;
  58.     ellipse(xLast, yLast, 5, 5);
  59.   }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement