したがって、以下のコードに従って粒子を使って正弦波の動きを作成する方法を知っています。しかし、私がしたいのは、ストリングに沿ったリップルのような効果を作り出すことです。アイデアは、ストリングに沿って波が動くのですが、現在波にないセクションはゼロの位置に戻り、実行されませんさらに1本の波がラインを通過します。これを達成するには、以下の正弦波運動をどのように修正すればよいですか?波の始まりがフラットに戻るようにラインの正弦波を作成する方法
int xspacing = 16; // How far apart should each horizontal location be spaced
int w; // Width of entire wave
float theta = 0.0; // Start angle at 0
float amplitude = 75.0; // Height of wave
float period = 500.0; // How many pixels before the wave repeats
float dx; // Value for incrementing X, a function of period and xspacing
float[] yvalues; // Using an array to store height values for the wave
void setup() {
size(640, 360);
w = width+16;
dx = (TWO_PI/period) * xspacing;
yvalues = new float[w/xspacing];
}
void draw() {
background(0);
calcWave();
renderWave();
}
void calcWave() {
// Increment theta (try different values for 'angular velocity' here
theta += 0.02;
// For every x value, calculate a y value with sine function
float x = theta;
for (int i = 0; i < yvalues.length; i++) {
yvalues[i] = sin(x)*amplitude;
x+=dx;
}
}
void renderWave() {
noStroke();
fill(255);
// A simple way to draw the wave with an ellipse at each location
for (int x = 0; x < yvalues.length; x++) {
ellipse(x*xspacing, height/2+yvalues[x], 16, 16);
}
}
私は、同じ方向にお互いを鏡映する2つの正弦波を持つことによって、左からチューブを握っているように、nの効果を作りたいと思っています。既に存在する例が分からない限り、私はあなたのメソッドを完成させるでしょう –
@SebastianZeki私のアプローチはうまくいくはずです。 –
私は本当にほしいと思うのは、正弦波の方法が一度だけ通過し、次に粒子が中立位置に戻ることです。どうすればいい?私はnoloop()を使ってみましたが、波が終わってから止めたいと思っていたので、すべてを止めました。 –