Created
October 8, 2014 13:42
-
-
Save OhJia/4b7973a2ec1fef078a9d to your computer and use it in GitHub Desktop.
This file contains 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
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