From ellipse() to curveVertex()
in
Programming Questions
•
15 days ago
Hi all.
Can someone tell me an elegant way to draw a waveform with sin() but with curveVertex? I use the following with ellipse, but I want to change it, however I can't find enough info and all my experiments failed.
Thanks!
- // Starting angle
- float theta = 0.0;
- void setup() {
- size(500, 300);
- smooth();
- }
- void draw() {
- background(255);
- // Increment theta (try different values for " angular velocity " here)
- theta += 0.02;
- noStroke();
- //stroke(1);
- fill(0);
- //noFill();
- float x = theta;
- // A for loop is used to draw all the points along a sine wave (scaled to the pixel dimension of the window).
- for (int i = 0; i <= width; i++) {
- float y = sin(x) * height/4;
- beginShape();
- ellipse(i*10, y + height/2+(1*10), 5, 5);
- ellipse(i*10, y + height/2+(2*10), 5, 5);
- ellipse(i*10, y + height/2+(3*10), 5, 5);
- x += 0.2;
- endShape();
- }
- }
1