growth

command module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2020 License: Unlicense Imports: 11 Imported by: 0

README

growth

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.

Build Status

Installation

Simply run

go get -u github.com/iand/growth

Documentation is at http://godoc.org/github.com/iand/growth

Usage

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 at $GOPATH/bin/growth

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 flag. See catalog/catalog.go for a list of pre-defined fractals. Use the -o flag to change the output filename.

Examples

tree-2

Image of tree-2 fractal

bent-big-h

Image of bent-big-h fractal

Grammar Expansion

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 < and > 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:

  1. F++F++F
  2. <F-F++F-F>++<F-F++F-F>++<F-F++F-F>
  3. <<F-F++F-F>-<F-F++F-F>++<F-F++F-F>-<F-F++F-F>>++<<F-F++F-F>-<F-F++F-F>++<F-F++F-F>-<F-F++F-F>>++<<F-F++F-F>-<F-F++F-F>++<F-F++F-F>-<F-F++F-F>>

Multiple rules can be specified. For example the sierpinksi-gasket example has a seed of F--F--F and two rules: F: F--F--F--GG and G: GG. These generate the following sequences:

  1. F--F--F
  2. <F--F--F--GG>--<F--F--F--GG>--<F--F--F--GG>
  3. <<F--F--F--GG>--<F--F--F--GG>--<F--F--F--GG>--<GG><GG>>--<<F--F--F--GG>--<F--F--F--GG>--<F--F--F--GG>--<GG><GG>>--<<F--F--F--GG>--<F--F--F--GG>--<F--F--F--GG>--<GG><GG>>

Plotting Symbols

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 F however 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

LICENSE

This is free and unencumbered software released into the public domain. For more information, see http://unlicense.org/ or the accompanying UNLICENSE file.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package plot implemants the Fractal Growth algorithm described in The Computational Beauty of Nature by Gary William Flake.
Package plot implemants the Fractal Growth algorithm described in The Computational Beauty of Nature by Gary William Flake.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL