Drawing Sine Waves Problem
in
Programming Questions
•
5 months ago
Hello, I can't figure out why this is happening... I'm drawing sine waves based on a frequency but the waves don't seem to properly represent the frequency given. For instance, when I use 100 as the frequency, the waveform drawn appears higher than when I use 440 as the frequency. I'd like nice smooth oscilloscope waveforms ideally, can anybody see what the problem is?
- int freq;
- void setup() {
- size(500, 500);
- stroke(255);
- strokeWeight(1);
- freq = 440;
- }
- void draw() {
- background(0);
- pushMatrix();
- translate(width/2, height/2);
- beginShape();
- for (int i = 0; i < 100; i++) {
- vertex(i, sin(i*freq)*20);
- }
- endShape(CLOSE);
- popMatrix();
- }
1