Balloon [] c = new Balloon [3];
void setup () {
size (500, 500);
c [0] = new Balloon (100, 300, 50);
c [1] = new Balloon (400, 300, 50);
c [2] = new Balloon (250, 400, 80);
}
void draw () {
background (255);
for (int i = 0; i<c.length; i++) {
c[i].display();
c[i].move_up();
}
}
class Balloon {
int x;
int y;
int r;
Balloon (int x, int y, int r) {
this.x = x;
this.y = y;
this.r = r;
}
void display () {
fill (255, 255, 0);
line (x, y, x, y+r);
ellipse (x, y, r, r);
}
void move_up () {
this.y = this.y -1;
if (this.y <= 10) {
this.y = height;
}
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น