Maintainer | byorgey@cis.upenn.edu |
---|---|

Safe Haskell | None |

Generate fractal trails by the "iterated subset" construction, iteratively replacing each segment with a given pattern.

- iterTrail :: Trail R2 -> [Trail R2]
- refineSegment :: Trail R2 -> Segment R2 -> Maybe (Trail R2)
- koch :: (PathLike p, V p ~ R2) => p
- levy :: (PathLike p, V p ~ R2) => p
- zag :: (PathLike p, V p ~ R2) => p
- sqUp :: (PathLike p, V p ~ R2) => p
- sqUpDown :: (PathLike p, V p ~ R2) => p
- sqUpDown' :: (PathLike p, V p ~ R2) => p
- snowflake :: Int -> Trail R2
- sqUpDownOverlay :: Renderable (Path R2) b => Diagram b R2
- data IterTrailConfig = ITC {}
- randITC :: (MonadRandom m, Applicative m) => m IterTrailConfig
- drawITC :: Renderable (Path R2) b => IterTrailConfig -> Diagram b R2
- drawITCScaled :: (Renderable (Path R2) b, Backend b R2) => IterTrailConfig -> Diagram b R2
- randIterGrid :: (Renderable (Path R2) b, Backend b R2) => IO (Diagram b R2)

# Iterated subset algorithm

iterTrail :: Trail R2 -> [Trail R2]Source

Given a "seed pattern", produce a list of successive refinements, where the nth trail in the list has iteratively had all segments replaced by the seed pattern n times, starting from a horizontal line. In other words, the zeroth trail in the output list is a horizontal unit segment, and each subsequent trail is equal to the previous with all segments replaced by the seed pattern.

import Diagrams.TwoD.Path.IteratedSubset iterTrailEx = vcat' with { sep = 0.3 } . map strokeT . take 5 $ iterTrail koch

refineSegment :: Trail R2 -> Segment R2 -> Maybe (Trail R2)Source

Use a trail to "refine" a segment, returning a scaled and/or rotated copy of the trail with the same endpoint as the segment.

# Examples

## Example seed trails

koch :: (PathLike p, V p ~ R2) => pSource

Seed for the Koch curve (side of the famous Koch `snowflake`

).

zag :: (PathLike p, V p ~ R2) => pSource

Strange zig-zag seed that produces a dense fractal path with lots of triangles.

sqUp :: (PathLike p, V p ~ R2) => pSource

A "square impulse" seed which produces a quadratic von Koch curve.

sqUpDown :: (PathLike p, V p ~ R2) => pSource

A "double square impulse" seed which produces fantastic rectilinear spiral patterns.

sqUpDown' :: (PathLike p, V p ~ R2) => pSource

Like `sqUpDown`

but with `cubicSpline`

applied to produce a curvy
version.

## Other stuff

A random collection of other fun things you can do with
`iterTrail`

. There is no particular emphasis on making these
configurable or generic; the point is just to suggest some fun
things you can do. If you want to play with them, copy the source
code and modify it as you see fit.

snowflake :: Int -> Trail R2Source

The famous Koch snowflake, made by putting three Koch curves
together. `snowflake n`

yields an order-`n`

snowflake.

sqUpDownOverlay :: Renderable (Path R2) b => Diagram b R2Source

A cool diagram featuring successive iterations of `sqUpDown'`

superimposed atop one another.

data IterTrailConfig Source

Parameters to generate an iterated subset fractal.

randITC :: (MonadRandom m, Applicative m) => m IterTrailConfigSource

Generate a random `IterTrailConfig`

. This features many
hard-coded values. If you want to play with it just copy the
code and modify it to suit.

drawITC :: Renderable (Path R2) b => IterTrailConfig -> Diagram b R2Source

Generate an iterated subset fractal based on the given parameters.

drawITCScaled :: (Renderable (Path R2) b, Backend b R2) => IterTrailConfig -> Diagram b R2Source

Like `drawITC`

, but also scales, centers, and pads the result so
that it fits nicely inside a 4x4 box.

randIterGrid :: (Renderable (Path R2) b, Backend b R2) => IO (Diagram b R2)Source

Create a grid of 100 random iterated subset fractals. Impress your friends!