在 processingjs 中,我遇到了麻烦。我写的代码有效,但只适用于一个圈子。如果有两个或更多圆圈,它们就会开始闪烁(我猜这是因为 background() 的刷新率很慢)。我的代码中有什么地方做错了吗(发布在下面),或者这只是 processingjs 速度的限制?
我确信必须有一种方法可以在没有滞后的情况下实现相同的效果。我已经看到在处理方面做得更多,延迟更少。
此外,当两个圆圈重叠时,它们也会开始闪烁(大约是两倍)。有没有办法解决这个问题?
我的代码:
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;
}
}