我繪製正弦波的代碼如下。 見下面我的代碼:用正在增加的頻率處理繪製正弦波
float x, y;
float prevX=0.0, prevY=0.0;
int numOfWaves = 6;
float angle = 0;
void setup()
{
size(360, 360);
background(0);
smooth();
stroke(255);
}
void draw()
{
translate(0, height/2);
scale(1, -1);
for(int count=0; count < 360; ++count){
x = count;
angle = radians(count);
y = sin(angle*(numOfWaves/2.0));
y = map(y,-1,1,-height/2,height/2);
line(prevX, prevY, x, y);
prevX = x;
prevY = y;
}
prevX = prevY = 0.0;
}
但我想正弦波的頻率增加了距離。 這是當前正弦波我得到:
我將如何做到這一點?
在最後一幅圖中,當您從左到右移動時,頻率*下降*,波長增加。這是你想要的,還是你想讓頻率增加到正確的位置,還是其他事情發生在圖形的一端? –