Module #13

 For this assignment, I created a simple animation in R. My animation is attached. 


First, I downloaded the animation package by Yihui Xie. Then, I created the animation loop: 


> library(animation)
> ani.options(interval = 0.1)
> col.range <- terrain.colors(15)
> saveGIF({
+   layout(matrix(c(1, 2), 2, 1, byrow = TRUE))
+   par(mar = c(2, 4, 2, 1))
+   
+   for (i in 1:100) {
+     x <- seq(-10, 10, length.out = 100)
+     y <- sin(x + i / 10) * exp(-abs(i / 50))
+     plot(x, y, type = 'l', col = col.range[i %% 15 + 1], ylim = c(-1, 1), main = "Sine Wave Progression", xlab = "X-axis", ylab = "Amplitude")
+     abline(h = 0, col = "gray")
+     
+     plot(1, type = "n", axes = FALSE, xlab = "", ylab = "", main = "Frame Number")
+     text(1, 1, labels = paste("Frame:", i), cex = 2)
+   }
+   
+ }, movie.name = "sine_wave_animation.gif", ani.width = 600, ani.height = 450, ani.path = "~/Desktop/")
Output at: sine_wave_animation.gif


##My animation loops through 100 waves, generating a sine wave with each phase shift. 
Animations such as mine can be great tools to visualize sound, color, and radio waves.


Comments

Popular posts from this blog

Module #11 Assignment

Module #12 Assignment

Module #9 Assignment