Phase of sin() wave problem
in
Programming Questions
•
1 year ago
Hi,
I have four dots oscillating horizontally. I am trying to get them to each oscillate a quarter wave out of phase with the next one.
Here's the basic sketch:
This gives weird behaviour.
Any help would be greatly appreciated.
Thanks,
Shane
I have four dots oscillating horizontally. I am trying to get them to each oscillate a quarter wave out of phase with the next one.
Here's the basic sketch:
- float x, angle;
void setup() {
size (600, 400);
}
void draw() {
background (127);
noStroke();
fill(0);
for (int i=1; i<5; i++) {
x = sin(radians(angle))*50;
ellipse (x + i*100, 100, 5, 5);
angle -= PI/4;
}
}
- float x, angle, phi;
void setup() {
size (600, 400);
}
void draw() {
background (127);
noStroke();
fill(0);
for (int i=1; i<5; i++) {
x = sin(radians(angle))*50;
ellipse (x + i*100 + phi, 100, 5, 5);
angle -= PI/4;
phi += PI/8;
}
}
This gives weird behaviour.
Any help would be greatly appreciated.
Thanks,
Shane
1