Advertisement
xeromino

step by step

Oct 12th, 2013
578
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. float x, y, prevX, prevY;
  2. int dir;
  3. color c;
  4. color[] palette = {
  5.   #BF245E,#EAB1AC,#291B36,#426175,#9DA9A3
  6. };
  7.  
  8. void setup() {
  9.   frameRate(20);
  10.   size(500, 300);
  11.   background(50);
  12.   c = int(random(palette.length));
  13.   fill(palette[c]);
  14.   x = 0;
  15.   y = random(height);
  16.   prevX = x;
  17.   prevY = y;
  18. }
  19.  
  20. void draw() {
  21.   float r = random(1);
  22.   if (r > .5) {
  23.     dir = 1;
  24.   }
  25.   else {
  26.     dir = -1;
  27.   }
  28.  
  29.   if (frameCount % 2 == 0) {
  30.     x += random(20, 40);
  31.   }
  32.   else {
  33.     x += random(10, 20);
  34.     y += random(10, 30)*dir;
  35.   }
  36.   fill(palette[c]);
  37.   stroke(240);
  38.   line(prevX, prevY, x, y);
  39.   ellipse(x, y, 8, 8);
  40.   prevX = x;
  41.   prevY = y;
  42.  
  43.   if (x > width || y > height || y < 0) {
  44.     reset();
  45.   }  
  46. }
  47.  
  48. void reset() {
  49.   c = int(random(palette.length));
  50.   fill(palette[c]);
  51.   x = 0;
  52.   prevX = x;
  53.   y = random(50,height-50);
  54.   prevY = y;
  55.   filter(BLUR);
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement