Last active
January 8, 2019 22:30
-
-
Save MartinMSPedersen/f36aad4cd9a3e238c24f6e4dbbf044d1 to your computer and use it in GitHub Desktop.
Hat number 3 in R
This file contains 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
x <- function(k, t) { | |
c( -sin(4*pi*k/1000) + sin(t)*sin(t/3)/5, | |
-0.5*sin(8*pi*k/1000) + cos(t)/2 | |
) | |
} | |
y <- function(k, t) { | |
c( -cos(2*pi*k/1000) + cos(t)*cos(t/3)/2, | |
-0.5*cos(4*pi*k/1000) + sin(t)/3 | |
) | |
} | |
# max_x <- -Inf | |
# min_x <- Inf | |
# max_y <- -Inf | |
# min_y <- Inf | |
png(file = "hat3-%03d.png", width = 120, height = 120) | |
par(bg = "black") | |
par(mar = rep(0,4)) | |
for (t in seq(0, 6*pi, length.out = 200)) { | |
plot.new() | |
plot.window(c(-1.2,1.2),c(-1.2,1.5)) | |
for (i in 0:999) { | |
# max_x <- max(max_x,x(i,t)) | |
# min_x <- min(min_x,x(i,t)) | |
# max_y <- max(max_x,x(i,t)) | |
# min_y <- min(min_x,x(i,t)) | |
lines(x(i,t), y(i,t), col = alpha(rgb(1,1,1), 0.3)) | |
} | |
} | |
dev.off() | |
system("convert -delay 1 hat3-*.png hat3.gif") | |
file.remove(list.files(pattern="hat3-.*.png")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment