【发布时间】:2016-12-29 00:18:34
【问题描述】:
我正在尝试使用 processing.js 将处理草图插入到我的 wordpress 博客中。
问题是我得到的是冻结的图像而不是移动的图像。就好像绘制函数没有循环一样。 (在我的电脑上,草图效果很好)
可能是什么原因造成的?我该如何解决?
<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>
【问题讨论】:
-
您可能想花几分钟格式化您的代码,以便它使用正确的缩进。如果不是为了我们的理智,那是为了你自己!
标签: wordpress processing processing.js