-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.txt
50 lines (42 loc) · 806 Bytes
/
code.txt
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
// Valkyrie_formative
/**
A ball that bounces around
*/
int h = 300;
int w = 500;
int ball_x = 100;
int ball_y = 100;
int ball_r = 20;
int ball_speed_x = 3;
int ball_speed_y = 3;
color ball_color = #ff0000;
color bg_color = #000000;
void setup() {
size(w,h);
frameRate(30);
}
void draw() {
refresh();
move_ball();
draw_ball();
}
void refresh() {
fill(bg_color);
rect(0, 0, w, h);
}
void move_ball() {
ball_x += ball_speed_x;
ball_y += ball_speed_y;
if(ball_x >= w-ball_r || ball_x <= ball_r) {
// we have hit the wall
ball_speed_x = -ball_speed_x;
}
if(ball_y >= h-ball_r || ball_y <= ball_r) {
// we have hit the ceiling or floor
ball_speed_y = -ball_speed_y;
}
}
void draw_ball() {
fill(ball_color);
ellipse(ball_x, ball_y, ball_r, ball_r);
}