我在下面做了Processing草图,以便我可以将它用作我博客的标题(通过Processing.js)。为什么Processing/Processing.js草图在运行时不显示?
它没有在我的博客(tumblr)工作,所以我尝试了在JavaScript模式下运行它,它也不能工作。
,当我在任Chrome或Safari上运行它,它不会显示。 我的其他* .pde草图工作正常,也使用P3D的那些工作正常,也以同样的方式使用鼠标输入的其他工作也很好......我不明白。
昨天我划伤了我的脑袋整天试图弄明白。谁能帮忙?
PShape s;
int nbPts = 500;
float AngleSpeed = 0.001;
int col = 0;
void setup() {
size(800, 600, P3D);
s = createShape();
s.beginShape();
for(int i = 0; i <= nbPts; i++) {
int x = int(random(width/10-width, width-width/10));
int y = int(random(height/10-height, height-height/10));
int z = int(random(width/10-width, width - width/10));
s.vertex(x, y, z);
}
s.endShape();
colorMode(HSB, 360, 100, 100);
ellipseMode(CENTER);
strokeWeight(10);
}
void draw() {
noFill();
background(col, 50, 100);
stroke(col, 50, 100);
translate(width/2, height/2, -width/2);
camera();
for (int i = 0; i < s.getVertexCount(); i++) {
float x = s.getVertexX(i);
float y = s.getVertexY(i);
float z = s.getVertexZ(i);
x += random(-1, 1);
y += random(-1, 1);
z += random(-1, 1);
s.setVertex(i, x, y, z);
}
s.disableStyle();
shape(s, 0, 0);
s.rotateY(AngleSpeed);
s.rotateX(random(0, AngleSpeed));
s.rotateZ(random(0, AngleSpeed));
pushMatrix();
translate(0, 0, -width/2);
fill(225, 0, 100);
ellipse(width/2, height/2, width, width);
popMatrix();
}
void mousePressed() {
col = int(random(0, 255));
for(int i = 0; i <= nbPts; i++) {
int x = int(random(width/10-width, width-width/10));
int y = int(random(height/10-height, height-height/10));
int z = int(random(width/10-width, width - width/10));
s.setVertex(i, x, y, z);
}
}
非常感谢,我不得不调整它一点使它工作我想要的方式。尽管看起来我不能在没有createShape()的情况下以这种方式获得透视效果。反正, ,再次感谢! –
这很奇怪。我用[printCamera()](https://processing.org/reference/printCamera_.html)和[printProjection()](https://processing.org/reference/printProjection_.html),看到参数相同在JS中,因为他们在Java中。也许他们呈现不同(出于某种原因)?就像你说的,做一些调整将会有所帮助。 ProcessingJS支持[perspective()](http://processingjs.org/reference/perspective_/)和[camera()](http://processingjs.org/reference/camera_/)。很高兴答案帮助:) –