Skip to content

ballesta25/Canvas-Fractals

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

Canvas Fractals

Simple fractal drawing program in blank-canvas

To see the results, run the program (e.g. runghc fractal.hs), then point a browser at localhost:3000.

Fractals are represented here as lazy infinite trees. The primary means of interacting with a fractal are the functions step, which returns the next level of the tree as a list and approximate which returns a Canvas () that draws an approximation to the 'rest of' the fractal at the current level - this is needed in order to bottom-out the recursion when drawing.

The mkFractal function generates Fractal data structures given a function that converts from a single line to the next level of the fractal. It applies this function recursively to every line in the fractal. The union constructor, (:+), combines two Fractals into a single Fractal object. It would be fairly simple to add a constructor based on arbitrary Canvas objects to allow fractals with components other than lines.

The drawLeaves and drawBranches functions both draw a representation of a given Fractal to a given depth, the first under the assumption that each level replaces the one before (as in the Koch curve), and the second under the assumption that it is added in instead (as in tree fractals where every level is drawn).

About

Simple fractal drawing program in Blank Canvas

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published