#这个代码加了定义之后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);
}
}