L-system: Difference between revisions
Content deleted Content added
m turned back into a draft task |
→{{header|Wren}}: Added the rabbit population example. |
||
Line 186:
=={{header|Wren}}==
{{libheader|DOME}}▼
{{libheader|Wren-lsystem}}
The source code for the Wren-lsystem module is available on this site by clicking the above link and then navigating to the Talk page.
We can use this to generate the results for the rabbit population example as follows.
<syntaxhighlight lang="wren">import "./lsystem" for LSystem, Rule
import "./fmt" for Fmt
var lsys = LSystem.new(
["I", "M"], // variables
[], // constants
"I", // axiom
[
Rule.new("I", "M"), // rules
Rule.new("M", "MI")
],
0 // angle (not needed here)
)
System.print("Step String")
System.print("---- --------")
for (i in 0..5) Fmt.print("$-4d $8m", i, lsys.iterate(i))</syntaxhighlight>
{{out}}
<pre>
Step String
---- --------
0 I
1 M
2 MI
3 MIM
4 MIMMI
5 MIMMIMIM
</pre>
▲{{libheader|DOME}}
We can also use it to draw a curve such as the Koch Snowflake.
<syntaxhighlight lang="wren">import "graphics" for Canvas, Color
import "dome" for Window
|