-
Notifications
You must be signed in to change notification settings - Fork 0
/
ball.pde
63 lines (58 loc) · 1.17 KB
/
ball.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
boolean pressed;
ball[] a= new ball[ball_ammount];
void mousePressed()
{
pressed=!pressed;
}
void draw_ball(ball[] a, int i)
{
fill(a[i].c);
ellipse(a[i].x, a[i].y, a[i].radius, a[i].radius);
}
void update_ball(ball[] a, int i)
{
if (a[i].y > height-a[i].radius/2)
{
a[i].y=height-a[i].radius/2;
a[i].speedY=-a[i].speedY;
}
if (a[i].y < a[i].radius/2)
{
a[i].y=a[i].radius/2;
a[i].speedY=-a[i].speedY;
}
if (a[i].x > width-a[i].radius/2)
{
a[i].x=width-a[i].radius/2;
a[i].speedX=-a[i].speedX;
}
if (a[i].x<a[i].radius/2)
{
a[i].x=a[i].radius/2;
a[i].speedX=-a[i].speedX;
}
a[i].x+=a[i].speedX;
a[i].y+=a[i].speedY;
}
void initialize(int ball_ammount, ball[] a)
{
for (int i=0; i<ball_ammount; i++)
{
a[i]=new ball();
}
for (int i=0; i<ball_ammount; i++)
{
a[i].radius=random(20, 40);
a[i].x=random(a[i].radius+1, width-a[i].radius-1);
a[i].y=random(a[i].radius+1, height-a[i].radius-1);
a[i].speedX=random(-3, 3);
a[i].speedY=random(-3, 3);
a[i].c=color(random(30,80), 0, random(50,120), 120);
}
}
public class ball {
float x, y;
float radius;
float speedX, speedY;
color c;
}