# it takes several seconds if 'redraw = TRUE'
oopt = ani.options(nmax = 500, interval = 0)
opar = par(mar = c(3, 2.5, 0.5, 0.2), pch = 20, mgp = c(1.5, 0.5, 0))
buffon.needle()
# this will be faster
buffon.needle(redraw = FALSE)
par(opar)
# create HTML animation page
ani.options(nmax = 100, interval = 0.1, ani.height = 500, ani.width = 600,
title = "Simulation of Buffon's Needle",
description = "There are three graphs made in each step: the top-left
one is a simulation of the scenario, the top-right one is to help us
understand the connection between dropping needles and the mathematical
method to estimate pi, and the bottom one is the result for each
dropping.")
ani.start()
par(mar = c(3, 2.5, 1, 0.2), pch = 20, mgp = c(1.5, 0.5, 0))
buffon.needle(type = "S")
ani.stop()
ani.options(oopt)
Run the code above in your browser using DataLab