-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathballs.pde
67 lines (51 loc) · 1.12 KB
/
balls.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
float x=50/2;
Ball [] balls;
int nballs=1000;
void setup(){
surface.setSize(1200,600);
background(0,0,0);
balls = new Ball[nballs];
for (int i=0; i<nballs; i++){
float d=random(10);
float x=random(d/2,width-d/2);
float y=random(height);
//color c=color(random(250),random(250),random(250));
color c=color(random(10,50),205,random(200,255));
float s = random(10);
balls[i] = new Ball(x,y,d,c,s);
}
}
void draw(){
frameRate(60);
background(0,0,0);
//x+=dx;
//ellipse(x,200,50,50);
for (int i = 0; i < nballs; i++) {
balls[i].display();
balls[i].move();
}
}
class Ball{
//parameters
color Color;
float centerX, centerY, diameter;
int sign=1;
float speed;
//initialize
Ball(float x, float y, float r, color c, float s){
centerX = x;
centerY = y;
diameter = r;
Color = c;
speed = s;
}
//functions
void display(){
fill(Color);
ellipse(centerX,centerY,diameter,diameter);
}
void move(){
centerX+=sign*speed;
if (centerX>width-diameter/2 || centerX< diameter/2 ){sign=-1*sign;}
}
}