MouseX为一波

MouseX for a wave

我是 Processing 的新手,我有一个简单的问题。

我有一个 mouseX 添加到一个 wave 中,所以左边的 wave 比右边的少。但是右边的波浪太大了。你知道如何解决这个问题吗?

int wave = int(sin(frameCount * 0.02 + ( x * y ) * 0.01) * mouseX);

sin() returns a value in the range [-1.0, 1.0]. Define the height at the left (h_left) and the height at the right (h_right) and interpolate between the values by the function lerp(),根据鼠标的相对x坐标((float)mouseX/width):

float h_left  = 100.0;
float h_right = 200.0;
float weight  = (float)mouseX/width;

float height  = lerp(h_left, h_right, weight);

int wave = int(sin(frameCount * 0.02 + ( x * y ) * 0.01) * height/2.0);