Skip to content

Instantly share code, notes, and snippets.

@OhJia
Created October 8, 2014 13: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 OhJia/4b7973a2ec1fef078a9d to your computer and use it in GitHub Desktop.
Save OhJia/4b7973a2ec1fef078a9d to your computer and use it in GitHub Desktop.
class Oscillator {
PVector angle;
PVector velocity;
PVector amplitude;
float a, b;
Oscillator(float _x, float _y) {
a = _x;
b = _y;
angle = new PVector();
velocity = new PVector(random(-0.05, 0.05), random(-0.05, 0.05));
//Random velocities and amplitudes
amplitude = new PVector(random(width/2), random(height/2));
}
void oscillate() {
angle.add(velocity);
}
void display() {
//Oscillating on the x-axis
float x = sin(angle.x)*amplitude.x;
//Oscillating on the y-axis
float y = sin(angle.y)*amplitude.y;
pushMatrix();
translate(a, b);
fill(random(0,255));
ellipse(x, y, 16, 16);
popMatrix();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment