Line-based fractal generator.
general concept
Generates fractal images by successively transforming an initial set of lines. A transformer function takes a single line and returns possibly many new lines. In each stage, we transform all lines in the current generation resulting in a new, usually larger set of lines. A line is defined by its start point, end point, width, and "done" value. When a line's done flag is set, that means we no longer transform it in following iterations.
implemented transformers
There are two example transformers in transformers.go. First, is the equilateral transformer which notches an equilateral triangle 1/3 of the way through the line:
Next is the tree transformer which branches each line with a bit of randomness in terms of angle and length. After a line is branched, the "done" flag is set so that it is not modified in future iterations.
usage
import (
"github.com/emef/fractals"
)
// create initial shape, just a triangle
lines := []fractals.Line{
fractals.NewLine(0, 0, 500, 0, 2.0),
fractals.NewLine(500, 0, 100, 50, 2.0),
fractals.NewLine(100, 50, 0, 0, 2.0)}
// fractal object, will transform each line according to EquilateralTransformer in each step
f := fractals.New(fractals.EquilateralTransformer, lines)
// advance 8 iterations
f.Next(8)
// save fractal to png
f.ToFile("png/equal_fractal.png")
examples generated by tests
Inspired by blog post: http://georgemdallas.wordpress.com/2014/05/02/what-are-fractals-and-why-should-i-care/