Created
November 1, 2022 10:29
-
-
Save savaged/91fbe78427b8ad34fd956fd3a156be01 to your computer and use it in GitHub Desktop.
Fun plotting a circle in the console
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
| open System | |
| let R = 18 | |
| let H = R * 2 | |
| let setDisplayPosition (x, y) = | |
| try | |
| Console.SetCursorPosition(x, y) | |
| with | |
| | :? ArgumentOutOfRangeException -> printfn "Attempted to set cursor out of range!" | |
| let prepDisplay = | |
| Console.Clear() | |
| setDisplayPosition(0, 0) | |
| let closeDisplay = setDisplayPosition(0, H * 2) // TODO figure out why the console truncates the 'circle' | |
| let T d = d * Math.PI / 180.00 | |
| let coord t (f: double -> double) = H + Convert.ToInt32((double R) * f(t)) | |
| let X t = coord t Math.Cos | |
| let Y t = coord t Math.Sin | |
| let coords d = X(T(d)), Y(T(d)) | |
| let circCoords = [1..360] |> List.map (fun d -> coords(d)) | |
| let plot (x, y) = | |
| setDisplayPosition(x, y) | |
| Console.Write('*') | |
| let plotCirc = | |
| prepDisplay | |
| circCoords |> List.iter (fun (x, y) -> plot(x, y)) | |
| closeDisplay | |
| plotCirc |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Need to work out why the F# version truncates the circle whereas the C# version does not.