float A = 50;
float ellipsex = 0;
float ellipsey = 0;
ArrayList Circles;
void setup() {
size(500, 500);
smooth();
Circles = new ArrayList();
for(int i = 0; i < 150; i++){
Circle myCircle = new Circle(random(0,width),random(0,200));
Circles.add(myCircle);
}
}
void draw() {
background(0);
if (mousePressed == true) {
ellipse(ellipsex, ellipsey, A, A);
ellipsex = ellipsex + ((mouseX-ellipsex)/20.0);
ellipsey = ellipsey + ((mouseY-ellipsey)/20.0);
}
if (mousePressed == true) {
fill(255, 0, 0);
}
else {
fill(255);
}
for(int i = 0; i < 150; i++){
Circle myCircle = (Circle) Circles.get(i);
myCircle.play();
}
}
class Circle {
float x = 0;
float y = 0;
float speedX = 3;
float speedY = 0.2;
Circle(float xx, float yy) {
x = xx;
y = yy;
}
void play() {
Thecircle();
movement();
bouncing();
force();
}
void force() {
speedY = speedY + 0.5;
}
void bouncing() {
if (x > width) {
speedX = speedX * -1;
}
if (x < 0) {
speedX = speedX * -1;
}
if (y > height) {
speedY = speedY * -1;
}
if (y < 0) {
speedY = speedY * -1;
}
}
void movement() {
x = x + speedX;
y = y + speedY;
}
void Thecircle() {
ellipse(x, y, 20, 20);
}
}

No comments:
Post a Comment