Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Ball{
- float x;
- float y;
- float d;
- float speedx;
- float speedy;
- color c;
- Ball(){
- x = random(100, 500);
- y = random(100, 500);
- d = random(5, 100);
- speedx = random(1, 5);
- speedy = random(1, 5);
- c = color(random(0, 255), random(0, 255), random(0, 255));
- }
- void display(){
- fill(c);
- ellipse(x, y, d, d);
- }
- void move(){
- x += speedx;
- y += speedy;
- }
- void reflect(){
- if (x > width || x < 0){
- speedx = -speedx;
- }
- if (y > height || y < 0){
- speedy = -speedy;
- }
- }
- }
- Ball[] balls;
- void setup(){
- size(600, 600);
- balls = new Ball[100];
- for (int i = 0; i < balls.length; i++){
- balls[i] = new Ball();
- }
- }
- void draw(){
- background(255);
- for (int i = 0; i < balls.length; i++){
- balls[i].display();
- balls[i].move();
- balls[i].reflect();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement