Created
December 8, 2012 10:00
-
-
Save smallgeek/4239664 to your computer and use it in GitHub Desktop.
KochCurve
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace TurtleGraphics.Library | |
| module KochCurve = | |
| open System | |
| let rec private move n (f: Action<int, int, int, int>) (t:Turtle) = | |
| match n with | |
| | 0 -> | |
| let rad = Math.PI / 180.0 | |
| let x = int (t.step * cos (rad * t.angle)) + t.x | |
| let y = int (t.step * sin (rad * t.angle)) + t.y | |
| f.Invoke(t.x, t.y, x, y) | |
| { t with x = x; y = y} | |
| | n -> | |
| [ 60.0; -120.0; 60.0 ] | |
| |> List.fold (fun t' a -> (move (n-1) f t').turn(a)) t | |
| |> move (n-1) f | |
| let private createTurtle n x y max = | |
| let t = { x = x; y = y; step = max / (3.0 ** float n); angle = 0.0; } | |
| t | |
| [<CompiledName "Navigate">] | |
| let navigate n x y max (f: Action<int, int, int, int>) = | |
| let t = createTurtle n x y max | |
| move n f t |> ignore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment