Advertisement
xeromino

rec3

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