mirror of
https://github.com/processing/processing4.git
synced 2026-02-18 21:05:36 +01:00
38 lines
684 B
Plaintext
38 lines
684 B
Plaintext
// The Nature of Code
|
|
// Daniel Shiffman
|
|
// http://natureofcode.com
|
|
|
|
// Attraction Array with Oscillating objects around each thing
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
|