Advertisement
xeromino

Waterfall

Nov 8th, 2013
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. int columns = 20;
  2. float col_sz, theta, theta2;
  3. Ball[][] ball = new Ball[columns][columns];
  4. color[] palette = {#838689, #A8CABA, #CAD7B2, #EBE3AA};
  5. color bg = #5D4157;
  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 i=0; i<columns; i++) {
  16.     int col = int(random(4));
  17.     theta = map(sin(theta2), -1, 1, 0, TAU);
  18.     theta2 += (TAU/12);
  19.     for (int j=0; j<columns; j++) {
  20.       x = col_sz/2+i*col_sz;
  21.       y = col_sz/2+j*col_sz;
  22.       ball[i][j] = new Ball(x, y, theta, col);
  23.       theta -= TAU/columns;
  24.     }
  25.   }
  26. }
  27.  
  28. void draw() {
  29.   background(bg);
  30.   for (int j=0; j<columns; j++) {
  31.     for (int i=0; i<columns; i++) {
  32.       ball[i][j].display();
  33.     }
  34.   }
  35. }
  36. class Ball {
  37.   float x, y, theta, sz;
  38.   int col;
  39.  
  40.   Ball(float _x, float _y, float _theta, int _col) {
  41.     x = _x;
  42.     y = _y;
  43.     theta = _theta;
  44.     col = _col;
  45.   }
  46.  
  47.   void display() {
  48.     fill(palette[col]);
  49.     sz = map(sin(theta), -1, 1, 0, col_sz*1.0);
  50.     ellipse(x, y, sz, sz);
  51.     theta += .0523;
  52.   }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement