Go package and executable that implements the Fractal Growth algorithm described in The Computational Beauty of Nature by Gary William Flake (MIT Press 2011). This algorithm generates self-similar fractals using a simple grammar-based approach called an L-System.
The L-System grammar consists of a starting point (the seed) and a set of expansion rules. The seed is used as the starting point and a sequence of symbols is generated by evaluating the grammar repeatedly over a fixed number of iterations. During each evaluation each symbol in the sequence is replaced with a new set of symbols using the grammar's rules.
The final sequence of symbols is converted into an image by a plotter which interprets the sequence as a list of movement commands for a simple turtle graphics system.
go get -u github.com/iand/growth
Documentation is at http://godoc.org/github.com/iand/growth
For full control, import the
github.com/iand/growth/plot package into your program, define a
Grammar and use a
Plotter to draw it. This repository contains a sample application in
growth.go that demonstrates how to control the generated image. If you ran the
go get command above then the application will have been compiled into an executable present
Run the executable to generate the default plot of the big-h fractal, which will be written to a
file called growth.png. The particular fractal to draw can be specified with the
-e command line
catalog/catalog.go for a list of pre-defined fractals. Use the
-o flag to change the output filename.
The sequence a string is initialised to the seed's value. On each iteration each rune in the string
is matched against the rules defined in the grammar. A new sequence string is built by replacing the
rune by the substitution defined in the rule, delimited by
> which indicate that the
plotter should step down in scale during this part of the sequence. If the rune does not match a
rule then it is simply copied into the new sequence.
As an example, given the seed
F++F++F and a rule
F: F-F++F-F the following sequences would be generated on each iteration:
Multiple rules can be specified. For example the
sierpinksi-gasket example has a seed of
and two rules:
F: F--F--F--GG and
G: GG. These generate the following sequences:
The Plotter interprets the following symbols. All others symbols are ignored.
F- move forward by the current step size and draw a line from the previous position to the new one
G- move forward by the current step size without drawing a line
+- rotate clockwise by the plotter's configured angle
-- rotate anticlockwise by the plotter's configured angle
[- save the current position and angle
]- restore the previous position and angle
|- identical behaviour to
Fhowever it is usually not expanded in a grammar so can be used to preserve scale
<- reduce the step size and line width by multiplying by StepDelta and LineWidthDelta
- '>' - restore the previous step size and line width
This is free and unencumbered software released into the public domain. For more
information, see http://unlicense.org/ or the accompanying