1

processingjsで困っています。私が書いたコードは機能しますが、1 つの円に対してのみです。2 つ以上の円がある場合、それらはちらつき始めます (これは、background() からのリフレッシュ レートが遅いためだと推測しています)。私のコード(以下に掲載)で間違っていることがありますか、それとも処理jsの速度の限界ですか?

ラグなしで同じ効果を達成する方法があるに違いないと確信しています。より少ないラグでより多くの処理が行われるのを見てきました。

さらに、2 つの円が重なると、ちらつきも始まります (約 2 倍)。それを修正する方法はありますか?

私のコード:


    int count;
    int[] circles;
    int numCircles;
    int color, color1, color2;
    void setup()
    {
    size($(document.body).width(),600);
    smooth();
    numCircles = 1;
    color = random(0,200);
    color1 = random(0, 200);
    color2 = random(0, 200);
    strokeWeight( 10 );
frameRate( 60 );

count = 0;
circles = new int[numCircles*4];
for(int x = 0; x<circles.length; x+=4)
{
    circles[x]=random(0,width);
    circles[x+1]=random(0,height);
    if(random(0,1)==0)
    {
     circles[x+2] = 1;
    }
    else
    {
     circles[x+2] = -1;
    }
    if(random(0,1)==0)
    {
     circles[x+3] = 1;
    }
    else
    {
     circles[x+3] = -1;
    }

}


}



void draw()
{


background(255);
fill(255);
stroke(color, color1, color2);

ellipse(circles[count], circles[count+1], 500, 500);
if(abs(circles[count]-width)<=10)
{circles[count+2]=-abs(circles[count+2])}
if(abs(circles[count+1]-height)<=10)
{circles[count+3]=-abs(circles[count+3])}

if(circles[count]<=10)
{
 circles[count+2] = abs(circles[count+2]);
}
if(circles[count+1]<=10)
{
 circles[count+3] = abs(circles[count+3]);
}
circles[count]+=circles[count+2];
circles[count+1]+=circles[count+3];

count+=4;
if(count>circles.length-4)
{count = 0;

}

}

4

1 に答える 1

0

私は自分が間違っていたことを理解しました

forループを介して描画関数の各円をループすることで、ちらつきの原因となったdraw()関数の反復間の遅延なしに、各円の位置を更新できることを発見しました。

于 2011-03-26T06:59:30.480 に答える