我正在使用这个草图,我无法弄清楚为什么不能在Javascript模式下工作。最奇怪的是,它没有显示任何明显的编译器错误。当我点击运行时,它会在Web浏览器上打开一个选项卡,但没有任何反应(在Chrome和Firefox上测试)。我检查了所有变量名称,并且没有与Processing中的任何类冲突(根据我在这里读到的内容)。事实上,我已经用西班牙语命名了所有变量,而且我没有使用任何库(本机或外部)。我目前在Win8东芝笔记本电脑上使用Processing 2.2.1 - 32位。我的代码:
Malla malla;
color color1, color2;
void setup()
{
size(600, 600, P2D);
smooth(8);
color1 = color(255, 0, 255);
color2 = color(255, 255, 0);
malla = new Malla(width*0.5, height*0.5, color1, color2);
background(0);
}
void draw()
{
fill(0, 24);
noStroke();
rect(0, 0, width, height);
malla.display();
}
//////////////////////////////////////////////////////////////////////////////////////
class Malla
{
Punto[] punto;
float distBase, factorDist, alfaMax, ancho, alto;
PVector temp1, temp2;
float tempDist, alfaStroke;
color color1, color2, colorStroke;
float minX, maxX, minY, maxY, factorColor;
Malla(float ancho, float alto, color color1, color color2)
{
this.ancho = ancho;
this.alto = alto;
this.color1 = color1;
this.color2 = color2;
distBase = sqrt(sq(ancho) + sq(alto));
factorDist = 0.1;
alfaMax = 16;
minX = (width - ancho)*0.5;
maxX = (width + ancho)*0.5;
minY = (height - alto)*0.5;
maxY = (height + alto)*0.5;
punto = new Punto[400];
for (int i = 0; i < punto.length; i++)
{
punto[i] = new Punto(ancho, alto);
}
}
void display()
{
for (int i = 0; i < punto.length; i++)
{
punto[i].update();
}
for (int i = 0; i < punto.length; i++)
{
for (int j = 0; j < punto.length; j++)
{
temp1 = punto[i].obtenerPos();
temp2 = punto[j].obtenerPos();
tempDist = PVector.dist(temp1, temp2);
alfaStroke = map(tempDist, 0, distBase*factorDist, alfaMax, 0);
alfaStroke = constrain(alfaStroke, alfaMax, 0);
if (tempDist < distBase*factorDist)
{
strokeWeight(1);
factorColor = map(temp1.x, minX, maxX, 0, 1);
colorStroke = lerpColor(color1, color2, factorColor);
stroke(red(colorStroke), green(colorStroke), blue(colorStroke), alfaStroke);
line(temp1.x, temp1.y, temp2.x, temp2.y);
}
}
}
}
}
class Punto
{
PVector pos, vel;
float ancho, alto;
float minX, maxX, minY, maxY;
float velMax;
Punto(float ancho, float alto)
{
this.ancho = ancho;
this.alto = alto;
velMax = 0.75;
minX = (width - ancho)*0.5;
maxX = (width + ancho)*0.5;
minY = (height - alto)*0.5;
maxY = (height + alto)*0.5;
pos = new PVector(random(minX, maxX), random(minY, maxY));
vel = new PVector(random(-1*velMax, velMax), random(-1*velMax, velMax));
}
void update()
{
if (dist(pos.x, pos.y, width*0.5, height*0.5) > sqrt(sq(ancho) + sq(alto))*0.5)
{
vel.mult(-1);
}
pos.add(vel);
}
PVector obtenerPos()
{
return pos;
}
}
希望有人可以帮助我,再见!