Skip to content

Instantly share code, notes, and snippets.

@jasoncoon
Created December 8, 2014 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasoncoon/5ee6c6344617a348bc9b to your computer and use it in GitHub Desktop.
Save jasoncoon/5ee6c6344617a348bc9b to your computer and use it in GitHub Desktop.
pendulum wave
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