Using animation guidance from: https://davetang.org/muse/2015/02/12/animated-plots-using-r/
devtools::load_all()
To use any of the animation functions you first need to save the output of a generated tree by setting the argument datadump = T during tree production. You do not have to set plot = F.
fractal_tree <- random_tree(splits = 9, children = 2, angle = pi/4, scale_angle = T, random_angles = T, sib_lgth_ratio = c(1.5,1),
sib_thk_ratio = c(1,1.5), random_lengths = T, angle_scale = 1.05, length_scale = 1.35, plot = T, datadump = T)
Generates a random field to create a GIF animation of a tree “swaying” in the wind.
fractal_tree : The output of random_trees() or
deterministic_tree() when datadump = T.
var :
(dbl) Indicates variance of the random field. Larger var =>
stronger “wind”.
scale : (dbl) Indicated timescale of wind
patterns. Smaller scale => faster wind direction changes.
return_filename : (lgl) Indicated if the file name of the
generated GIF should be returned.
filename <- swaying_tree(fractal_tree, var = 0.02, scale = 0.4, return_filename = T)
Example:
The object used to generate the “wind” is calculated in the manner below.
model <- RandomFields::RMexp(var = 0.02, scale = 0.4)
branch_count <- sum(cumprod(fractal_tree$fun_variables$children)) + 1
x <- seq(0, 10, length.out = 100)
y <- seq(0, 10, length.out = branch_count)
simu <- suppressMessages(as.matrix(RandomFields::RFsimulate(model, x, y, grid=TRUE)))
raster::plot(raster::raster(simu))
Produces a GIF animation of a “growing” tree. The only input is the datadump output of one the tree generating functions and the argument indicating whether the filename should be returned. Produces ten frames per tree level, including level of starter branch/trunk, plus ten more frames for the final image.
filename <- growing_tree(fractal_tree, return_filename = T)
Example: