-
Notifications
You must be signed in to change notification settings - Fork 6
/
balls.R
35 lines (29 loc) · 797 Bytes
/
balls.R
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
library(raylibr)
width <- 600
height <- 400
n <- 1000
sizes <- runif(n, 2, 20)
xs <- runif(n, sizes, width - sizes)
ys <- runif(n, sizes, height - sizes)
dxs <- rnorm(n)
dys <- rnorm(n)
cs <- sample(colors(), n, replace = TRUE)
cs <- lapply(cs, fade, 0.7)
set_target_fps(100)
init_window(width, height, "R & Raylib: Bouncing Balls")
while (!window_should_close()) {
xs <- xs + (dxs / 2)
ys <- ys + (dys / 2)
oobx <- (xs >= (width - sizes)) | (xs <= sizes)
ooby <- (ys >= (height - sizes)) | (ys <= sizes)
dxs[oobx] <- dxs[oobx] * -1
dys[ooby] <- dys[ooby] * -1
xs <- xs + (dxs / 2)
ys <- ys + (dys / 2)
begin_drawing()
clear_background("white")
draw_circle(xs, ys, sizes, cs)
draw_text(paste0("fps: ", get_fps()), 20, 20, 20, "blue")
end_drawing()
}
close_window()