-
-
Save wilsonfreitas/48e3ef30887aac42dac9e25865907958 to your computer and use it in GitHub Desktop.
Como gerar GIF com animação com R
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
f <- function(x) cos(x*20) | |
expi <- function(x) cos(x) + sin(x)*1i | |
par(mfrow = c(1,2)) | |
L <- 40 | |
medias_Re <- c() | |
fs <- c() | |
as <- seq(0.01, 1, l = 140) | |
animation::saveGIF({ | |
for(a in as) { | |
x <- seq(0, a*40, l = 500) | |
ft <- expi(x)*f(x/(a*L)) | |
media_Re <- mean(Re(ft)) | |
plot(Re(ft), Im(ft), xlim = c(-1.2, 1.2), ylim = c(-1.2, 1.2), main = "cos(20t) - Mass Center on Complex Plane") | |
points(media_Re, mean(Im(ft)), col = "red", cex = 3, pch = 16 ) | |
medias_Re <- c(medias_Re, media_Re) | |
fs <- c(fs, a*L) | |
plot(fs, medias_Re, type = "l", xlim = c(0, 40), ylim = c(-0.11, 0.51)) | |
points(a*L, media_Re, col = "red", cex = 3, pch = 16) | |
Sys.sleep(0.1) | |
} | |
}, interval = 0.1, ani.width = 600, ani.height = 300) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment