SHARE
TWEET

bubblegum

xeromino Apr 25th, 2014 222 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. boolean saveAnim = false;
  2. float frm, a;
  3. int numElem = 150;
  4. myDot[] myDots = new myDot[numElem];
  5. color bg = #202020;
  6. color[] palette = {
  7.   #F58F12, #0B9EE7, #4EA731, #F4D910, #F334E3
  8. };
  9.  
  10. void setup() {
  11.   size(400, 400);
  12.   background(bg);
  13.   noStroke();
  14.   float locx, locy, start_sz, r;
  15.   color col;
  16.  
  17.   for (int i=0; i<numElem; i++) {
  18.     locx = random(width);
  19.     locy = random(height);
  20.     start_sz = random(8, 15);
  21.     col = palette[int(random(5))];
  22.     r = random(TWO_PI);
  23.     myDots[i]= new myDot(locx, locy, start_sz, col, r);
  24.   }
  25. }
  26.  
  27. void draw() {
  28.   fill(bg);
  29.   rect(0, 0, width, height);
  30.   for (int i=0; i<numElem; i++) {
  31.     myDots[i].display(i);
  32.   }
  33.  
  34.   if (saveAnim) {
  35.     if (frameCount % 4 == 0 && frameCount < frm+121) saveFrame("image-###.gif");
  36.   }
  37. }
  38.  
  39. void keyPressed() {
  40.   saveAnim = true;
  41.   frm = frameCount;
  42. }
  43.  
  44. void mouseClicked() {
  45.   setup();
  46. }
  47.  
  48. class myDot {
  49.   float locx, locy, start_sz, sz, r, x, y;
  50.   color col;
  51.   int dir=1;
  52.  
  53.   myDot(float _locx, float _locy, float _start_sz, color _col, float _r) {
  54.     locx = _locx;
  55.     locy = _locy;
  56.     start_sz = _start_sz;
  57.     col = _col;
  58.     r = _r;
  59.     x = random(-20, 20);
  60.     y = random(-20, 20);
  61.     if (random(1)>.5) dir =-1;
  62.   }
  63.  
  64.   void display(float i) {
  65.     pushMatrix();
  66.     translate(locx, locy);
  67.     rotate(r);
  68.     sz = map(sin(r), -1, 1, 5, start_sz*4);
  69.     a = 200;
  70.     fill(col,a);
  71.     rect(x, y, sz, sz, sz/3);
  72.     popMatrix();
  73.     r += 0.0523*dir;
  74.   }
  75. }
RAW Paste Data
Top