Skip to content

Commit 6b584e4

Browse files
committed
Do not use @example in code chunks
1 parent ec37851 commit 6b584e4

8 files changed

Lines changed: 124 additions & 124 deletions

File tree

docs/src/tutorials/algae.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Lindermayer as one of the first L-systems.
1818
First, we need to load the VPL metapackage, which will automatically load all
1919
the packages in the VPL ecosystem.
2020

21-
````@example algae
21+
````julia
2222
using VirtualPlantLab
2323
````
2424

@@ -36,7 +36,7 @@ include type definitions in a module to avoid having to restart the Julia
3636
session whenever we want to redefine them. Because each module is an independent
3737
namespace, we need to import `Node` from the VPL package inside the module:
3838

39-
````@example algae
39+
````julia
4040
module algae
4141
import VirtualPlantLab: Node
4242
struct A <: Node end
@@ -50,7 +50,7 @@ the nodes, so types `A` and `B` do not require fields.
5050

5151
The axiom is simply defined as an instance of type of `A`:
5252

53-
````@example algae
53+
````julia
5454
axiom = algae.A()
5555
````
5656

@@ -77,7 +77,7 @@ relationship between two nodes and `[]` indicates branching.
7777

7878
The implementation of the two rules of algae growth model in VPL is as follows:
7979

80-
````@example algae
80+
````julia
8181
rule1 = Rule(algae.A, rhs = x -> algae.A() + algae.B())
8282
rule2 = Rule(algae.B, rhs = x -> algae.A())
8383
````
@@ -87,7 +87,7 @@ Note that in each case, the argument `rhs` is being assigned an anonymous (aka
8787
in the assigment to the argument. That is, the Julia expression `x -> A() + B()`
8888
is equivalent to the following function definition:
8989

90-
````@example algae
90+
````julia
9191
function rule_1(x)
9292
algae.A() + algae.B()
9393
end
@@ -103,15 +103,15 @@ With the axiom and rules we can now create a `Graph` object that represents the
103103
algae organism. The first argument is the axiom and the second is a tuple with
104104
all the rewriting rules:
105105

106-
````@example algae
106+
````julia
107107
organism = Graph(axiom = axiom, rules = (rule1, rule2))
108108
````
109109

110110
If we apply the rewriting rules iteratively, the graph will grow, in this case
111111
representing the growth of the algae organism. The rewriting rules are applied
112112
on the graph with the function `rewrite!()`:
113113

114-
````@example algae
114+
````julia
115115
rewrite!(organism)
116116
````
117117

@@ -125,7 +125,7 @@ interactive version of the graph will be drawn and one can zoom and pan with the
125125
mouse (in this online document a static version is shown, see
126126
[Backends](../manual/Visualization.md) for details):
127127

128-
````@example algae
128+
````julia
129129
import GLMakie
130130
draw(organism)
131131
````
@@ -137,15 +137,15 @@ purposes (this will be explained in more advanced examples).
137137

138138
Applying multiple iterations of rewriting can be achieved with a simple loop:
139139

140-
````@example algae
140+
````julia
141141
for i in 1:4
142142
rewrite!(organism)
143143
end
144144
````
145145

146146
And we can verify that the graph grew as expected:
147147

148-
````@example algae
148+
````julia
149149
draw(organism)
150150
````
151151

docs/src/tutorials/context.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ parent node that was captured. Note that that now, the rhs component gets a new
3434
argument, which corresponds to the context of the father node captured in the
3535
lhs.
3636

37-
````@example context
37+
````julia
3838
using VirtualPlantLab
3939
module types
4040
using VirtualPlantLab
@@ -63,21 +63,21 @@ all the `Cell` nodes. A `Query` object is created by passing the type of the
6363
node to be queried as an argument to the `Query` function. Then, to actually
6464
execute the query we need to use the `apply` function on the graph.
6565

66-
````@example context
66+
````julia
6767
getCell = Query(Cell)
6868
apply(pop, getCell)
6969
````
7070

7171
If we rewrite the graph one we will see that a second cell now has a state of 1.
7272

73-
````@example context
73+
````julia
7474
rewrite!(pop)
7575
apply(pop, getCell)
7676
````
7777

7878
And a second iteration results in all cells have a state of 1
7979

80-
````@example context
80+
````julia
8181
rewrite!(pop)
8282
apply(pop, getCell)
8383
````
@@ -93,7 +93,7 @@ the `state` of each node in a vector (unlike Rules and Queries, this function
9393
takes the actual node as argument rather than a `Context` object, see the
9494
documentation for more details):
9595

96-
````@example context
96+
````julia
9797
pop = Graph(axiom = axiom, rules = rule)
9898
states = Int64[]
9999
traverse_dfs(pop, fun = node -> push!(states, node.state))
@@ -102,7 +102,7 @@ states
102102

103103
Now the states of the nodes are in the same order as they were created:
104104

105-
````@example context
105+
````julia
106106
rewrite!(pop)
107107
states = Int64[]
108108
traverse_dfs(pop, fun = node -> push!(states, node.state))

docs/src/tutorials/forest.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ growth of these trees vary across individuals following a predefined distributio
1414
The data types, rendering methods and growth rules are the same as in the binary
1515
tree example:
1616

17-
````@example forest
17+
````julia
1818
using VirtualPlantLab
1919
using Distributions, Plots, ColorTypes
2020
import GLMakie
@@ -53,7 +53,7 @@ import .TreeTypes
5353

5454
Create geometry + color for the internodes
5555

56-
````@example forest
56+
````julia
5757
function VirtualPlantLab.feed!(turtle::Turtle, i::TreeTypes.Internode, data)
5858
# Rotate turtle around the head to implement elliptical phyllotaxis
5959
rh!(turtle, data.phyllotaxis)
@@ -65,7 +65,7 @@ end
6565

6666
Create geometry + color for the leaves
6767

68-
````@example forest
68+
````julia
6969
function VirtualPlantLab.feed!(turtle::Turtle, l::TreeTypes.Leaf, data)
7070
# Rotate turtle around the arm for insertion angle
7171
ra!(turtle, -data.leaf_angle)
@@ -80,7 +80,7 @@ end
8080

8181
Insertion angle for the bud nodes
8282

83-
````@example forest
83+
````julia
8484
function VirtualPlantLab.feed!(turtle::Turtle, b::TreeTypes.BudNode, data)
8585
# Rotate turtle around the arm for insertion angle
8686
ra!(turtle, -data.branch_angle)
@@ -89,7 +89,7 @@ end
8989

9090
Rules
9191

92-
````@example forest
92+
````julia
9393
meristem_rule = Rule(TreeTypes.Meristem, rhs = mer -> TreeTypes.Node() +
9494
(TreeTypes.Bud(), TreeTypes.Leaf()) +
9595
TreeTypes.Internode() + TreeTypes.Meristem())
@@ -126,7 +126,7 @@ of each tree and rotates it.
126126
(ii) Wrap the axiom, rules and the creation of the graph into a function that
127127
takes the required parameters as inputs.
128128

129-
````@example forest
129+
````julia
130130
function create_tree(origin, growth, budbreak, orientation)
131131
axiom = T(origin) + RH(orientation) + TreeTypes.Internode() + TreeTypes.Meristem()
132132
tree = Graph(axiom = axiom, rules = (meristem_rule, branch_rule),
@@ -138,7 +138,7 @@ end
138138
The code for elongating the internodes to simulate growth remains the same as for
139139
the binary tree example
140140

141-
````@example forest
141+
````julia
142142
getInternode = Query(TreeTypes.Internode)
143143

144144
function elongate!(tree, query)
@@ -166,13 +166,13 @@ of 2 meters. First we generate the original positions of the trees. For the
166166
position we just need to pass a `Vec` object with the x, y, and z coordinates of
167167
the location of each TreeTypes. The code below will generate a matrix with the coordinates:
168168

169-
````@example forest
169+
````julia
170170
origins = [Vec(i,j,0) for i = 1:2.0:20.0, j = 1:2.0:20.0]
171171
````
172172

173173
We may assume that the initial orientation is uniformly distributed between 0 and 360 degrees:
174174

175-
````@example forest
175+
````julia
176176
orientations = [rand()*360.0 for i = 1:2.0:20.0, j = 1:2.0:20.0]
177177
````
178178

@@ -181,22 +181,22 @@ LogNormal and Beta distribution, respectively. We can generate random
181181
values from these distributions using the `Distributions` package. For the
182182
relative growth rate:
183183

184-
````@example forest
184+
````julia
185185
growths = rand(LogNormal(-2, 0.3), 10, 10)
186186
histogram(vec(growths))
187187
````
188188

189189
And for the budbreak parameter:
190190

191-
````@example forest
191+
````julia
192192
budbreaks = rand(Beta(2.0, 10), 10, 10)
193193
histogram(vec(budbreaks))
194194
````
195195

196196
Now we can create our forest by calling the `create_tree` function we defined earlier
197197
with the correct inputs per tree:
198198

199-
````@example forest
199+
````julia
200200
forest = vec(create_tree.(origins, growths, budbreaks, orientations));
201201
nothing #hide
202202
````
@@ -214,22 +214,22 @@ as you may need to change some settings in your computer).
214214
We can simulate the growth of each tree by applying the method `simulate` to each
215215
tree, creating a new version of the forest (the code below is an array comprehension)
216216

217-
````@example forest
217+
````julia
218218
newforest = [simulate(tree, getInternode, 2) for tree in forest];
219219
nothing #hide
220220
````
221221

222222
And we can render the forest with the function `render` as in the binary tree
223223
example but passing the whole forest at once
224224

225-
````@example forest
225+
````julia
226226
render(Scene(newforest))
227227
````
228228

229229
If we iterate 4 more iterations we will start seeing the different individuals
230230
diverging in size due to the differences in growth rates
231231

232-
````@example forest
232+
````julia
233233
newforest = [simulate(tree, getInternode, 15) for tree in newforest];
234234
render(Scene(newforest))
235235
````
@@ -243,7 +243,7 @@ and execute the iterations of the loop in multiple threads using the macro `@thr
243243
Note that the rendering function can also be ran in parallel (i.e. the geometry will be
244244
generated separately for each plant and the merge together):
245245

246-
````@example forest
246+
````julia
247247
using Base.Threads
248248
newforest = deepcopy(forest)
249249
@threads for i in eachindex(forest)
@@ -254,7 +254,7 @@ render(Scene(newforest), parallel = true)
254254

255255
An alternative way to perform the simulation is to have an outer loop for each timestep and an internal loop over the different trees. Although this approach is not required for this simple model, most FSP models will probably need such a scheme as growth of each individual plant will depend on competition for resources with neighbouring plants. In this case, this approach would look as follows:
256256

257-
````@example forest
257+
````julia
258258
newforest = deepcopy(forest)
259259
for step in 1:15
260260
@threads for i in eachindex(newforest)
@@ -271,7 +271,7 @@ tweaking the 3D representation. When we want to combine plants generated from gr
271271
geometric element it is best to combine all these geometries in a `GLScene` object. We can start the scene
272272
with the `newforest` generated in the above:
273273

274-
````@example forest
274+
````julia
275275
scene = Scene(newforest);
276276
nothing #hide
277277
````
@@ -284,15 +284,15 @@ above when we determined the origin of each plant. VPL offers some shortcuts: `O
284284
passing the desired length as input. Below, a rectangle is created on the XY plane with the origin as a
285285
corner and each side being 11 units long:
286286

287-
````@example forest
287+
````julia
288288
soil = Rectangle(length = 21.0, width = 21.0)
289289
rotatey!(soil, pi/2)
290290
VirtualPlantLab.translate!(soil, Vec(0.0, 10.5, 0.0))
291291
````
292292

293293
We can now add the `soil` to the `scene` object with the `add!` function.
294294

295-
````@example forest
295+
````julia
296296
VirtualPlantLab.add!(scene, mesh = soil, color = RGB(1,1,0))
297297
````
298298

@@ -302,7 +302,7 @@ your code but also to help setup the scene (e.g. if you are not sure how big the
302302
Howver, it may be distracting for the visualization. It turns out that we can turn that off with
303303
`show_axes = false`:
304304

305-
````@example forest
305+
````julia
306306
render(scene, axes = false)
307307
````
308308

@@ -312,7 +312,7 @@ we can run the `save_scene` function on the object returned from `render`. The a
312312
`render` to increase the number of pixels in the final image. A helper function `calculate_resolution` is provided to
313313
compute the resolution from a physical width and height in cm and a dpi (e.g., useful for publications and posters):
314314

315-
````@example forest
315+
````julia
316316
res = calculate_resolution(width = 16.0, height = 16.0, dpi = 1_000)
317317
output = render(scene, axes = false, resolution = res)
318318
export_scene(scene = output, filename = "nice_trees.png")

0 commit comments

Comments
 (0)