2201_75500681 2023-01-20 22:13 采纳率: 100%
浏览 132
已结题

processing代码出错

#这个代码加了定义之后void setup()还有void draw()都无法运行,就连最简单的size()都运行不起来但是把定义删了size();就能运行了。 会提示语法错误。但我感觉我定义也是对的,为什么运行不起来.

他会提示Missing operator, semicolon, or ‘}’ near ‘setup’?


ArrayList<Ball> balls;
PImage=img;
float s=1.8;
import processing.sound.*;
AudioIn input;
Amplitude loundness;
void setup(){
  fullScreen (P2D) ;
  smooth();
  noStroke();
  balls = new ArrayList <Ball> () ;
  img = loadImage ("2.jpg") ;
  img.resize((int) (img. width*s), (int) (img. height*s));
  
  input = new AudioIn(this, 0) ;
  input. start ();
  loudness = new Amplitude (this) ;
  loudness.input (input) ;
}

void draw() {
  float inputLevel = 0.5;//map (mouseY, 0, height, 1.0, 0. 0);
  input. amp (inputLevel);
  float volume  = loudness. analyze ();
  for (int i = 30; i<map (volume, 0, 0.5, 1, 200); i+=2) {
    int x = int (random (img.width));
    int y = int (random (img.height));
    color pix = img.get (x, y);
    int a = (int) random (4);
    if (a == 2)
      balls. add (new Ball(0, height/2, x, y, pix)) ;
    else if (a == 1)
      balls. add (new Ball(width, height/2, x, y, pix));
    else if (a == 2)
      balls. add (new Ball(width/2, 0, x, y, pix));
     else
     balls. add (new Ball(width/2, height, x, y, pix));
  }
  background(255);
  for (int i=0; i<=balls.size()-1; i++) {
    Ball ball=balls.get(i);
    ball.move();
    ball.display();
    if (ball.finishied()) {
      balls.remove(i);
    }
  }
}

这是小球的类程序


class Ball {
  float x;
  float y;
  float size=random(5, 15);
  float life=255;
  color c;
  float x0=0;
  float y0=height/2;
  Ball(float _x0, float _y0, float tempX, float tempY, color _c) {
    x=tempX+width/2-img.width/2;
    y=tempY=height/2-img.heigh/2;
    c=_c;
    x0=_x0;
    y0=_y0;
  }

  void move() {
    x0+=(x-x0)/50.0;
    y0+=(y-y0)/50.0;
  }
  boolean finished() {
    if (!cheak)
      life--;
    if (life<0) {
      return true;
    } else {
      return false;
    }
  }

  void display() {
    fill(c, life);
    ellipse(x0, y0, size, size);
  }
}
  • 写回答

5条回答 默认 最新

  • 社区专家-Monster-XH 2023-01-20 22:36
    关注

    我发现了几个错误,请您检查一下:

    1.PImage=img; 应该写成 PImage img;
    2.fullScreen (P2D) ; 中应该是 fullScreen (P2D);
    3.img.resize((int) (img.widths), (int) (img.heights)); 中应该是img.width和img.height而不是img.width和img.heigh。
    4.在 Ball 类中的 y=tempY=height/2-img.heigh/2; 应该是 y=tempY+height/2-img.height/2;
    5.在 Ball 类中的 if (!cheak) 应该是 if (!finished())
    修改以上错误后应该可以解决这个问题。如果还有其他错误或者不清楚的地方,请再次提问。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

问题事件

  • 系统已结题 2月4日
  • 已采纳回答 1月27日
  • 创建了问题 1月20日

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分