Jump to content

L-system: Difference between revisions

2,293 bytes added ,  1 month ago
Added Quackery.
(Added FreeBASIC)
(Added Quackery.)
Line 243:
[[File:Kochsnowflakefractal.png|thumb|center|alt=fractal image|Koch Snowflake]]
 
=={{header|Quackery}}==
 
This solution reproduces the method used in other, pre-existing, tasks including [[Cantor set#Quackery|Cantor set]], [[Hilbert curve#Quackery|Hilbert curve]], [[Padovan sequence#Quackery|Padovan sequence]], [[Peano curve#Quackery|Peano curve]], [[Sierpinski curve#Quackery|Sierpinski curve]], and [[Sierpinski square curve#Quackery|Sierpinski square curve]].
 
The alphabet is a set of single character (of necessity) Quackery words, which are uppercase by convention (to distinguish them from, and avoid conflict with, other Quackery words, which are exclusively lowercase by convention.)
 
Rules are Quackery words in the alphabet which return a string as a result. The word <code>expand</code> takes an axiom (a string of rules) and applies the rule associated with each character sequentially and concatenates the returned strings. In other words it performs a single iteration of the L-system. The word <code>times</code> can be used to perform a specified number of iterations.
 
This example illustrates this method for the life cycle of the Gallifreyan Fibonacci Rabbit, which lives forever, matures after the first cycle, and thereafter [https://tardis.fandom.com/wiki/Bi-generation bi-generates], producing a single kitten (i.e. an immature rabbit) on every cycle.
 
<syntaxhighlight lang="Quackery"> [ $ "" swap witheach
[ nested quackery join ] ] is expand ( $ --> $ )
 
[ $ "M" ] is I ( --> $ )
[ $ "MI" ] is M ( --> $ )
 
$ "I" 5 times expand echo$</syntaxhighlight>
 
{{out}}
 
<pre>MIMMIMIM</pre>
 
Interpreting the resulting string is implemented by stepping through each character of the string and applying the actions associated with each character in the alphabet. In most of the tasks listed above this is achieved with the Quackery equivalent of a switch statement. Here, the action is to increment either a count of the number of mature rabbits, or the number of kittens, both of which are maintained on the stack, so <code>char I = if dip 1+</code> is sufficient.
 
<syntaxhighlight lang="Quackery"> [ 0 0 rot witheach
[ char I = if dip 1+ ]
say "Rabbits: " echo cr
say "Kittens: " echo cr ] is countrabbits ( $ --> )
 
$ "I" 5 times expand countrabbits</syntaxhighlight>
 
{{out}}
 
<pre>Rabbits: 5
Kittens: 3</pre>
 
=={{header|Phix}}==
1,496

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.