void mousePressed(){ onPressed = true; if (showInstruction){ background(0); showInstruction = false;} } void mouseReleased(){ onPressed = false; } void keyPressed(){ if (key =='c'){ for (int i=pts.size()-1; i>-1; i--){ Particle p = pts.get(i); pts.remove(i) ;} background(0);}} class Particle{ PVector loc,vel,acc; int lifeSpan,passedLife; boolean dead; float alpha,weight,weightRange,decay,xoffset,yoffset; color c; Particle(float x,float y,float xoffset,float yoffset){ loc=new PVector(x,y); float randDegrees=random(360); vel=new PVector(cos(radians(randDegrees)),sin(radians(randDegrees))); vel.mult(random(5)); acc=new PVector(0,0); lifeSpan = int(random(30,90)); decay = random(0.75,0.9); c = color(random(255),random(255),255); weightRange = random(3,50); this.xoffset=xoffset; this.yoffset=yoffset; } void update(){ if(passedLife>=lifeSpan){ dead = true; }else{ passedLife++;} alpha=float(lifeSpan-passedLife)/lifeSpan*70+50; weight=float(lifeSpan-passedLife)/lifeSpan*weightRange; acc.set(0,0); float rn=(noise((loc.x+frameCount+xoffset)*0.01,(loc.y+frameCount+yoffset)*0.01)-0.5)*4*PI; float mag=noise((loc.y+frameCount)*0.01,(loc.x+frameCount)*0.01); PVector dir=new PVector()cos(rn),sin(rn)); acc.add(dir); acc.mult(mag); float randDegrees=random(360); PVector randV=new PVector(cos(radians(randDegrees)),sin(radians(randDegrees))); randV.mult(0.5); acc.add(randV); vel.add(acc); vel.mult(decay); vel.limit(3); loc.add(vel);} void display(){ strokeWeight(weight+1.5); stroke(0,alpha); point(loc.x,loc.y); strokeWeight(weight); stoke(c); point(loc.x,loc.y); }为什么错了
时间: 2024-03-19 12:40:03 浏览: 137
drawingTool_java.rar_java画图_画图JAVA_画图板 java
5星 · 资源好评率100%
这段代码中存在几处错误,我来帮你逐一解释:
1. `lifeSpan,passedLife` 这行代码中,逗号应该被替换为分号。
2. `xoffset` 和 `yoffset` 在 `Particle` 类的构造函数中并没有被正确地声明为成员变量。应该将它们声明为 `this.xoffset` 和 `this.yoffset`。
3. 在 `Particle` 类的 `display()` 函数中,`stoke()` 应该被替换为 `stroke()`。
除了上述的错误之外,整个代码片段中缺少了一些必要的声明和变量初始化,例如 `ArrayList<Particle> pts` 和 `boolean onPressed` 等。你需要在代码的其他部分进行声明和初始化才能让它正确运行。
另外,为了更好地帮助你解决问题,我建议你提供更多的上下文信息和错误提示,这样我可以更准确地指出问题所在。
阅读全文