Created
December 22, 2020 14:37
-
-
Save georgemsavva/41360b98331306638e7368c64866560f to your computer and use it in GitHub Desktop.
Geometric animation
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
# You'll need to install ffmpeg to make this work. | |
# Creates a lot of pngs and an mp4 in the working directory, | |
# and will overwrite anything with the same name | |
# so be careful. | |
lt <- 600 | |
mt <- 400 | |
t <- seq(0,mt,l=lt) | |
a <- 1 # I don't use 'a' in this particular animation. | |
d <- expand.grid(a=a, t=t) | |
li <- seq(0,2,l=600)[-1] | |
for(ai in 1:length(li)){ | |
d <- within(d, { | |
z1 <- (1i*cos(2*t*pi)*(1) +(sin(2*t*pi))*(1) ) ; | |
z <- z1*(3+(sin(2*Arg(z1)+li[ai]*3*pi)* | |
cos(2*Arg(z1)*cos(1*Arg(z1)-pi*li[ai]*2)))) | |
}) | |
l=4 | |
png(filename=sprintf("escape%05d.png",ai), type="cairo", width=1000,height=1000) | |
par(mar=c(0,0,0,0), bg="#fafafa") | |
plot(NA, axes=F, xlim=c(-l,l), ylim=c(-l,l)) | |
by(d, INDICES=list(d$a), FUN=function(d2){ | |
points(d2$z, col="black", pch=20, lwd=0.5, cex=0.5, type="l") | |
}) | |
dev.off() | |
} | |
shell("ffmpeg -framerate 40 -i escape%05d.png -c:v libx264 -vf \"format=yuv420p\" -loop 0 -y escape.mp4") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment