A fractal generator for Unity3D inspired by Benoit Mandelbrot's initiator-generator scheme as described in his The Fractal Geometry of Nature.
Move the contents of the Assets folder to the desired locations in your Unity project.
The most basic components are the Fractal and Generator. The Generator is essentially an abstract data type, but inherits MonoBehaviour so that you can easily organize various Generator in a scene (See the Example scene). A Generator describes how a generic line segment in a fractal will be divided. This is achieved by creating control points along the line with specific diplacements, then iteratively dividing these newly created line segments in the same way (but in their own local orientation) up to maxIteration.
Add control points along the line by adding elements to the Vector3 list generators. These control points are positioned a percentage - specified by the x parameter [0-1] - along the line (the length of which is specified later in the Fractal component), and displacements (as percentages of the line length) in the local up and right directions - specified by the y and z paramenters respectively.
Now, on a seperate GameObject with a Fractal component attached, specify the generator property to be your Generator object. Specify the length of the initiator line segment and set renderPath to true. The initiator line will have beginning vertex at transform.localPosition and terminating vertex at transform.localPosition + transform.forward*length.
Upon playing the scene, Fractal will report its approximate fractal dimension, and its vertex count, the positions of which are made available as a Vector3 array in the path property. If renderPath is true, a LineRenderer will draw the fractal by connecting each of the vertices.
There are a few scripts included that make it easy to draw, view and capture complex, animated fractals. Check out the Example project for more details. These scripts are, in summary:
FreeFlyCamera - Attach to a camera script to fly around the scene. Bind whatever keys you like.
CameraCapture - Attach to a camera and press "K" while playing (or bind your own key) to render its view to images of arbitrary resolution. Can also capture a series of images seperated by burstInterval seconds for creating GIFS, etc. During a single run, filenames will increment. Between runs it will overwrite files that collide with the specified path.
Tracer - Attach to any GameObject and specify the fractal property to trace that fractal's path at the specified speed.
TraceReplicator - Create copies of Tracer and optionally randomize their starting position along the fractal.
Cloner - Create instances of a GameObject source by either rotating it around a pivot, translating it along the pivot or scaling it by the components of pivot.
The above Koch Curve is generated with the following parameters:
More complex geometric forms can be created with very subtle tweaks, the above curve is created with the parameters: