Created
December 8, 2014 21:42
-
-
Save jasoncoon/5ee6c6344617a348bc9b to your computer and use it in GitHub Desktop.
pendulum wave
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final float WAVE_HEIGHT = 16; | |
final float SPACING = 1; | |
final int NUM_BALL = 32; | |
final int BALL_RADIUS = 1; | |
int timeStep = 0; | |
//WAVE_HEIGHT, SPACING, and NUM_BALL all affect the size of the window. BALL_RADIUS does not. | |
void setup() { | |
size((int)(WAVE_HEIGHT * 2), (int)(WAVE_HEIGHT * 2)); | |
/* | |
stroke(255); | |
noFill(); | |
*/ | |
fill(255); | |
noStroke(); | |
ellipseMode(CENTER); | |
} | |
void draw() { | |
background(0); | |
for (int i = 0; i < NUM_BALL; i++) { | |
ellipse(SPACING * i, getY(i, timeStep), BALL_RADIUS, BALL_RADIUS); | |
} | |
timeStep++; // += 2 to go faster | |
} | |
float getY(int i, int t) { | |
return WAVE_HEIGHT * (1 + sin((float)(timeStep * (i / 500f + 0.02f)) % TWO_PI)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment