Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int columns = 20;
- float col_sz, theta, theta2;
- Ball[][] ball = new Ball[columns][columns];
- color[] palette = {#838689, #A8CABA, #CAD7B2, #EBE3AA};
- color bg = #5D4157;
- void setup() {
- //frameRate(20);
- size(400, 400);
- background(bg);
- noStroke();
- col_sz = width/columns;
- theta = PI/2;
- float x, y;
- for (int i=0; i<columns; i++) {
- int col = int(random(4));
- theta = map(sin(theta2), -1, 1, 0, TAU);
- theta2 += (TAU/12);
- for (int j=0; j<columns; j++) {
- x = col_sz/2+i*col_sz;
- y = col_sz/2+j*col_sz;
- ball[i][j] = new Ball(x, y, theta, col);
- theta -= TAU/columns;
- }
- }
- }
- void draw() {
- background(bg);
- for (int j=0; j<columns; j++) {
- for (int i=0; i<columns; i++) {
- ball[i][j].display();
- }
- }
- }
- class Ball {
- float x, y, theta, sz;
- int col;
- Ball(float _x, float _y, float _theta, int _col) {
- x = _x;
- y = _y;
- theta = _theta;
- col = _col;
- }
- void display() {
- fill(palette[col]);
- sz = map(sin(theta), -1, 1, 0, col_sz*1.0);
- ellipse(x, y, sz, sz);
- theta += .0523;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement