wk13

 

wk13.R

assas

2023-04-09

library(animation)

# Create a function to plot a bouncing ball
bounce_ball
<- function() {
 
for (i in 1:50) {
    plot.new()
    plot.window(
xlim = c(0, 100), ylim = c(0, 100))
    x
<- 50
    y
<- abs(100 * sin(i * pi/10))
    symbols(x, y,
circles = 5, inches = FALSE, add = TRUE)
    Sys.sleep(
0.1)
  }
}

# Create the animation
ani.record(
reset = TRUE) 
bounce_ball()            

ani.replay()             

saveGIF({
  bounce_ball()
},
interval = 0.1, movie.name = "bouncing_ball.gif")

## Output at: bouncing_ball.gif

## [1] TRUE


This R code generates a basic animation that shows a blue dot moving horizontally from left to right. The animation package is utilized along with a custom function called 'moving_dot' to create a series of plots. The animation is captured with 'ani.record', played back using 'ani.replay', and can be saved as a GIF file through the 'saveGIF' function.

Comments