我绘制正弦波的代码如下。 见下面我的代码:用正在增加的频率处理绘制正弦波
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;
}
但我想正弦波的频率增加了距离。 这是当前正弦波我得到:
我将如何做到这一点?
在最后一幅图中,当您从左到右移动时,频率*下降*,波长增加。这是你想要的,还是你想让频率增加到正确的位置,还是其他事情发生在图形的一端? –