Advertisement
xeromino

waves

Nov 1st, 2013
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. int columns = 20;
  2. float col_sz, theta, theta2;
  3. Ball[][] ball = new Ball[columns][columns];
  4. color[] palette = {#BD1550, #E97F02, #F8CA00, #8A9B0F};
  5. color bg = #490A3D;
  6.  
  7. void setup() {
  8.   frameRate(20);
  9.   size(400, 400);
  10.   background(bg);
  11.   noStroke();
  12.   col_sz = width/columns;
  13.   theta = PI/2;
  14.   float x, y;
  15.   for (int j=0; j<columns; j++) {
  16.     int col = j%4;
  17.     //theta = noise(j*4)*TAU;
  18.     theta = map(sin(theta2),-1,1,0,TAU);
  19.     theta2 += TAU/12;
  20.     for (int i=0; i<columns; i++) {
  21.       x = col_sz/2+i*col_sz;
  22.       y = col_sz/2+j*col_sz;
  23.       ball[i][j] = new Ball(x, y, theta, col);
  24.       theta -= TAU/columns;
  25.     }
  26.   }
  27. }
  28.  
  29. void draw() {
  30.   background(bg);
  31.   for (int j=0; j<columns; j++) {
  32.     for (int i=0; i<columns; i++) {
  33.       ball[i][j].display();
  34.     }
  35.   }
  36.  
  37.   if (frameCount % 2 == 0 && frameCount<61) saveFrame("image-####.gif");
  38.  
  39. }
  40. class Ball {
  41.   float x, y, theta, sz;
  42.   int col;
  43.  
  44.   Ball(float _x, float _y, float _theta, int _col) {
  45.     x = _x;
  46.     y = _y;
  47.     theta = _theta;
  48.     col = _col;
  49.   }
  50.  
  51.   void display() {
  52.     fill(palette[col]);
  53.     sz = map(sin(theta), -1, 1, 0, col_sz*1.0);
  54.     ellipse(x, y, sz, sz);
  55.     theta += (2*.0523);
  56.   }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement