ArrayList particles; void setup() { size(800,800); particles = new ArrayList(); smooth(); } void draw() { particles.add(new Particle()); background(255); for (int i = 0; i < particles.size(); i++ ) { Particle p = (Particle) particles.get(i); p.run();
来源:学生作业帮助网 编辑:作业帮 时间:2024/08/29 04:32:32
ArrayList particles; void setup() { size(800,800); particles = new ArrayList(); smooth(); } void draw() { particles.add(new Particle()); background(255); for (int i = 0; i < particles.size(); i++ ) { Particle p = (Particle) particles.get(i); p.run();
ArrayList particles;
void setup() {
size(800,800);
particles = new ArrayList();
smooth();
}
void draw() {
particles.add(new Particle());
background(255);
for (int i = 0; i < particles.size(); i++ ) {
Particle p = (Particle) particles.get(i);
p.run();
p.gravity();
p.display();
}
if (particles.size() > 100) {
particles.remove(0);
}
}
ArrayList particles; void setup() { size(800,800); particles = new ArrayList(); smooth(); } void draw() { particles.add(new Particle()); background(255); for (int i = 0; i < particles.size(); i++ ) { Particle p = (Particle) particles.get(i); p.run();
ArrayList particles; //定义一个动态数组particles
void setup() { //构造函数
size(800,800); //大小为800X800
particles = new ArrayList(); //创建一个新的ArrayList类型的对象particles数组
smooth(); //调用smooth方法
}
void draw() {
particles.add(new Particle()); //particles数组调用add方法添加一个新的对象
background(255); //背景颜色
for (int i = 0; i < particles.size(); i++ ) { //根据数组的大小循环
Particle p = (Particle) particles.get(i); /×取出数组particles第i个的值
p.run(); 并强制转换为Particle的类型
p.gravity(); 并把值赋给Particle类型对象p
p.display(); ×/
}
if (particles.size() > 100) { //当数组particles的大小大于100时
particles.remove(0); 调用remove方法
}
}