Copyright | (c) 2012 Brent Yorgey |
---|---|
License | BSD-style (see LICENSE) |
Maintainer | byorgey@cis.upenn.edu |
Safe Haskell | None |
Language | Haskell2010 |
Generate fractal trails by the "iterated subset" construction, iteratively replacing each segment with a given pattern.
- iterTrail :: Trail' Line R2 -> [Trail' Line R2]
- refineSegment :: Trail' Line R2 -> Segment Closed R2 -> Maybe (Trail' Line R2)
- koch :: (TrailLike t, V t ~ R2) => t
- levy :: (TrailLike t, V t ~ R2) => t
- zag :: (TrailLike t, V t ~ R2) => t
- sqUp :: (TrailLike t, V t ~ R2) => t
- sqUpDown :: (TrailLike t, V t ~ R2) => t
- sqUpDown' :: (TrailLike t, V t ~ R2) => t
- 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' Line R2 -> [Trail' Line 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 strokeLine . take 5 $ iterTrail koch
refineSegment :: Trail' Line R2 -> Segment Closed R2 -> Maybe (Trail' Line 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 :: (TrailLike t, V t ~ R2) => t Source
Seed for the Koch curve (side of the famous Koch snowflake
).
zag :: (TrailLike t, V t ~ R2) => t Source
Strange zig-zag seed that produces a dense fractal path with lots of triangles.
sqUp :: (TrailLike t, V t ~ R2) => t Source
A "square impulse" seed which produces a quadratic von Koch curve.
sqUpDown :: (TrailLike t, V t ~ R2) => t Source
A "double square impulse" seed which produces fantastic rectilinear spiral patterns.
sqUpDown' :: (TrailLike t, V t ~ R2) => t Source
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 R2 Source
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 R2 Source
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 IterTrailConfig Source
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 R2 Source
Generate an iterated subset fractal based on the given parameters.
drawITCScaled :: (Renderable (Path R2) b, Backend b R2) => IterTrailConfig -> Diagram b R2 Source
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!