Created
February 17, 2016 13:56
-
-
Save RCura/af35587c6c8f3e9ebd35 to your computer and use it in GitHub Desktop.
test R animation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(animation) | |
oopt = ani.options(interval = 0.1) | |
pp <- function(N) { | |
x1 <- runif(N, 0, N) | |
y1 <- runif(N, 0, N) | |
par(ann = F, bg = 'darkblue', pch = 8, mar = rep(0, 4)) | |
x <- seq(1, 30 * N) | |
j <- sample(x, 30) | |
plot(1, ann = F, type = 'n', axes = F, xlim = c(0, N), ylim = c(0, N)) | |
points(j, N - 1.5 * rep(1, 30), col = 'white', cex = 2) | |
interval = ani.options('interval') | |
for (i in 2:N) { | |
x <- seq(1, 30 * N) | |
x <- x[-j] | |
j <- c(sample(x, 30), j) | |
plot(1, ann = F, type = 'n', axes = F, xlim = c(0, N), ylim = c(0, N)) | |
y <- N - 1.5 * rep(1:i, rep(30, i)) | |
points(j, y, col = 'white', cex = 2) | |
z <- sample(N, length(x1), replace = T) | |
points(x1[i], y1[i], col = N - i, cex = 3) | |
points(x1[i + 1], y1[i + 1], col = N - i - 1, cex = 2.5) | |
l1 <- rawToChar(as.raw(c(0x4a, 0x6f, 0x79, 0x65, 0x75, 0x78, 0x20, 0x41, 0x6e, | |
+ 0x6e, 0x69, 0x76, 0x65, 0x72, 0x73, 0x61, 0x69, 0x72, 0x65))) | |
l2 <- rawToChar(as.raw(c(0x50, 0x61, 0x75, 0x6c))) | |
text(N/2, N/2, l1, srt = 360 * i/N, col = rainbow(N)[i], cex = 4.5 * i/N) | |
text(N/2, N/3, l2, srt = 360 * i/N, col = rainbow(N)[i], cex = 4.5 * i/N) | |
ani.pause() | |
} | |
} | |
pp(100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment