-
Notifications
You must be signed in to change notification settings - Fork 0
/
animated_tree.Rmd
77 lines (46 loc) · 2.73 KB
/
animated_tree.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
---
title: Animated Tree
output: github_document
---
Using animation guidance from: https://davetang.org/muse/2015/02/12/animated-plots-using-r/
```{r, message = F}
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 <b>datadump = T</b> during tree production. You do not have to set <b>plot = F</b>.
```{r, message = F, warning = F, fig.align='center'}
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)
```
## Swaying Tree
Generates a random field to create a GIF animation of a tree "swaying" in the wind.
#### Input arguments
<b>fractal_tree</b> : The output of <b>random_trees()</b> or <b>deterministic_tree()</b> when <b>datadump = T</b>.<br>
<b>var</b> : (dbl) Indicates variance of the random field. Larger <b>var</b> => stronger "wind".<br>
<b>scale</b> : (dbl) Indicated timescale of wind patterns. Smaller <b>scale</b> => faster wind direction changes.<br>
<b>return_filename</b> : (lgl) Indicated if the file name of the generated GIF should be returned.
```{r}
filename <- swaying_tree(fractal_tree, var = 0.02, scale = 0.4, return_filename = T)
```
Example:
<center><img src="swaying_trees/`r noquote(filename)`"></center>
The object used to generate the "wind" is calculated in the manner below.
```{r, fig.align='center'}
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))
```
## Growing Tree
Produces a GIF animation of a "growing" tree. The only input is the <b>datadump</b> 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.
```{r}
filename <- growing_tree(fractal_tree, return_filename = T)
```
Example:
<center><img src="growing_trees/`r noquote(filename)`"></center>
## Additional Examples
<center><img src="swaying_trees/swaying_tree_2020-12-07_23:14:52_PST.gif"></center>
<center><img src="growing_trees/growing_tree_2020-12-07_23:15:38_PST.gif"></center>
<center><img src="swaying_trees/swaying_tree_2020-12-07_23:20:40_PST.gif"></center>
<center><img src="growing_trees/growing_tree_2020-12-07_23:21:42_PST.gif"></center>