-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhysics1.bcc
More file actions
84 lines (64 loc) · 1.5 KB
/
Physics1.bcc
File metadata and controls
84 lines (64 loc) · 1.5 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
int width = 400;
int height = 400;
float r = 5.;
list<list<float>> updatePoints(list<list<float>> points) {
int i = 0;
while(i < list_size(points)) {
list<float> point = list_get(points, i);
float x = list_get(point, 0);
float y = list_get(point, 1);
float vx = list_get(point, 2);
float vy = list_get(point, 3);
vy = vy + .01;
x = x + vx;
y = y + vy;
if(x < r) {
x = r;
vx = -vx;
}
if(y < r) {
y = r;
vy = -vy;
}
if(x > cast<float>(width) - r) {
x = cast<float>(width) - r;
vx = -vx;
}
if(y > cast<float>(height) - r) {
y = cast<float>(height) - r;
vy = -vy;
}
point = list_set(point, 0, x);
point = list_set(point, 1, y);
point = list_set(point, 2, vx);
point = list_set(point, 3, vy);
points = list_set(points, i, point);
i = i + 1;
}
return points;
}
list<list<float>> points = [
[100., 100., .5, .9],
[300., 200., -.4, .6],
[200., 300., .8, -.5]
];
window_size(width, height);
while(true) {
window_pollMsg();
if(window_shouldClose())
break;
window_clear(200, 200, 200);
set_color(255, 0, 0);
window_point(window_mouseX(), window_mouseY(), 10);
points = updatePoints(points);
int i = 0;
while(i < list_size(points)) {
list<float> point = list_get(points, i);
float x = list_get(point, 0);
float y = list_get(point, 1);
set_color(0, 0, 0);
window_point(cast<int>(x), cast<int>(y), cast<int>(r));
i = i + 1;
}
window_flip();
}