mirror of
https://github.com/processing/processing4.git
synced 2026-02-12 01:50:44 +01:00
36 lines
691 B
Plaintext
36 lines
691 B
Plaintext
// Attraction Array with Oscillating objects around each thing
|
|
// Daniel Shiffman <http://www.shiffman.net>
|
|
// Nature of Code, Spring 2009
|
|
|
|
class Oscillator {
|
|
|
|
// Because we are going to oscillate along the x and y axis we can use PVector for two angles, amplitudes, etc.!
|
|
float theta;
|
|
float amplitude;
|
|
|
|
Oscillator(float r) {
|
|
|
|
// Initialize randomly
|
|
theta = 0;
|
|
amplitude = r;
|
|
|
|
}
|
|
|
|
// Update theta and offset
|
|
void update(float thetaVel) {
|
|
theta += thetaVel;
|
|
}
|
|
|
|
// Display based on a location
|
|
void display(PVector loc) {
|
|
float x = map(cos(theta),-1,1,0,amplitude);
|
|
|
|
stroke(0);
|
|
fill(50);
|
|
line(0,0,x,0);
|
|
ellipse(x,0,8,8);
|
|
}
|
|
}
|
|
|
|
|