L-system: Difference between revisions
Content deleted Content added
→{{header|Wren}}: Rabbit population example now uses new 'listSteps' method. |
Added FreeBASIC |
||
Line 115: | Line 115: | ||
After 5 iterations there are 5 old rabbits and 3 young ones (MIMMIMIM) |
After 5 iterations there are 5 old rabbits and 3 young ones (MIMMIMIM) |
||
</pre> |
</pre> |
||
=={{header|FreeBASIC}}== |
|||
L-system functionality as a Role that may be mixed in to a scalar. |
|||
<syntaxhighlight lang="vbnet">Sub Lindenmayer(s As String, rules() As String, count As Integer) |
|||
Dim As Integer i, j, k, found |
|||
Dim As String nxt, c, rep |
|||
For i = 0 To count |
|||
Print s |
|||
nxt = "" |
|||
For j = 1 To Len(s) |
|||
c = Mid(s, j, 1) |
|||
found = 0 |
|||
For k = Lbound(rules) To Ubound(rules) Step 2 |
|||
If c = rules(k) Then |
|||
rep = rules(k + 1) |
|||
found = 1 |
|||
Exit For |
|||
End If |
|||
Next k |
|||
nxt &= Iif(found = 1, rep, c) |
|||
Next j |
|||
s = nxt |
|||
Next i |
|||
End Sub |
|||
Dim As String rules(3) = {"I", "M", "M", "MI"} |
|||
Lindenmayer("I", rules(), 5) |
|||
Sleep</syntaxhighlight> |
|||
{{out}} |
|||
<pre>I |
|||
M |
|||
MI |
|||
MIM |
|||
MIMMI |
|||
MIMMIMIM</pre> |
|||
Also see:</br> |
|||
[[Dragon_curve#FreeBASIC]]</br> |
|||
[[Hilbert_curve#FreeBASIC]]</br> |
|||
[[Koch_curve#FreeBASIC]]</br> |
|||
[[Peano_curve#FreeBASIC]]</br> |
|||
[[Penrose_tiling#FreeBASIC]]</br> |
|||
[[Sierpinski_curve#FreeBASIC]]</br> |
|||
[[Sierpinski_arrowhead_curve#FreeBASIC]]</br> |
|||
[[Sierpinski_square_curve#FreeBASIC]]</br> |
|||
among others... |
|||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |