我正在尝试使用processing.js将处理草图插入到我的wordpress博客中。处理js没有循环绘制功能
问题是,我得到一个冻结的图像,而不是一个移动的。就好像绘图功能没有循环一样。 (在我的电脑上,素描效果很好)
可能是什么原因呢?我该如何解决它?
<script type="text/processing" data-processing-target="MySketch">
ball[] balls;
int numBalls = 20;
void setup(){
size (300,300,P3D);
background(255);balls=new ball[numBalls];
for(int i=0; i<numBalls;i++){
float r=random(5,20);
balls[i] = new ball(random(r,width-r),random(r,height-r),0,r,random(-1,10),random(-1,10));
}
}
void draw(){
background(255);
for(int i=0; i<numBalls;i++){
ball b; b=balls[i];
b.drawBall();
b.moveBall();
b.boundaries();
}
}
class ball{
float x;
float y;
float z;
float r;
float vx;
float vy;
ball(float x1,float y1,float z1,float r1,float vx1,float vy1){
x=x1;
y=y1;
z=z1;
r=r1;
vx=vx1;
vy=vy1;
}
void drawBall(){
noStroke();
fill(255,0,0);
lights();
pushMatrix();
translate(x, y,z);
sphere(r);
popMatrix();
}
void moveBall(){
x=x+vx;
y=y+vy;
}
void boundaries(){
if(x>=width-r || x<0+r)
vx=vx*-1;
if(y>=height-r || y<0+r)
vy=vy*-1;
}
}
</script>
<canvas id="MySketch"></canvas>
您可能想花几分钟格式化代码,以便使用正确的缩进。如果不是为了我们的理智,那为了你自己! –