Advertisement
xeromino

rec2

Feb 11th, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. int f, elements = 20;
  2. float[] sz = new float[elements];
  3. float[] rot = new float[elements];
  4. int[] col = new int[elements];
  5. color[] palette = {
  6.   #EFFFCD, #555152, #DCE9BE, #2E2633, #99173C
  7. };
  8. float theta, rotOff, scal;
  9. boolean save;
  10.  
  11. void setup() {
  12.   size(500, 500);
  13.   rectMode(CENTER);
  14.   float Sz = width*.75;
  15.  
  16.   for (int i=0; i<elements; i++) {
  17.     Sz -= random(10, 20);
  18.     sz[i] = Sz ;
  19.     rot[i]= PI/elements*i;
  20.     col[i] = (int) random(0, 5);
  21.   }
  22. }
  23.  
  24. void draw() {
  25.   background(20);
  26.   translate(width/2, height/2);
  27.  
  28.   for (int i=0; i<elements; i++) {
  29.     pushMatrix();
  30.     rotOff = map(sin(rot[i]+theta), -1, 1, -20, 20);
  31.     scal = map(sin(rot[i]+theta),-1,1,.7,2);
  32.     rotate(radians(rotOff));
  33.     fill(palette[i%5]);
  34.     noStroke();
  35.     rect(0, 0, sz[i]*scal, sz[i]*scal, 20);
  36.     popMatrix();
  37.   }
  38.   theta += 0.0523;
  39.  
  40.   if (save) {
  41.     if (frameCount%4==0 && frameCount<f+121) saveFrame("image-###.gif");
  42.   }
  43. }
  44.  
  45. void mouseClicked() {
  46.   setup();
  47. }
  48.  
  49. void keyPressed() {
  50.   f = frameCount;
  51.   save = true;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement