Created
October 15, 2014 18:31
-
-
Save robertpi/a0ae7537acc73242353b to your computer and use it in GitHub Desktop.
This file contains 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.Windows.Forms | |
open System.Drawing | |
let dt = 0.01 | |
let sigma=10. | |
let beta=8./3. | |
let rho=28.0 | |
let lorentzDeriv x y z dt sigma beta rho = | |
x + (dt * (sigma * (y - x))), | |
y + (dt * (x * (rho - z) - y)), | |
z + (dt * (x * y - beta * z)) | |
let rec points (x, y, z) i = | |
seq { if i < 1000 then | |
yield (x, y, z) | |
let point' = lorentzDeriv x y z dt sigma beta rho | |
yield! points point' (i + 1) } | |
let distance = 35. | |
let xOffSet = 0.5 | |
let yOffSet = 0.5 | |
let map3dTo2d (x3d, y3d, z3d) = | |
let x2d = xOffSet + (x3d / (z3d + distance)) | |
let y2d = xOffSet + (y3d / (z3d + distance)) | |
x2d, y2d | |
let form = | |
let form = new Form() | |
let xMax = float form.ClientSize.Width | |
let yMax = float form.ClientSize.Height | |
let bmp = new Bitmap(int xMax, int yMax) | |
let setPoint x y = | |
let x' = int (x * xMax) | |
let y' = int (y * yMax) | |
if 0 <= x' && x' < (int xMax) && | |
0 <= y' && y' < (int yMax) then | |
bmp.SetPixel(x', y', Color.Black) | |
let series = points (0.1, 0.1, 0.1) 0 | |
for (x, y, z) in series do | |
let x', y' = map3dTo2d (x, y, z) | |
setPoint x' y' | |
form.BackgroundImage <- bmp | |
form | |
[<EntryPoint>] | |
let main argv = | |
Application.Run form | |
0 // return an integer exit code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment