Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open System
- open System.Drawing
- open System.Drawing.Imaging
- open System.Runtime.InteropServices
- let CalcZ (coord:float * float) =
- let maxIterations = 255
- let rec CalcZHelper (xCoord:float) (yCoord:float) // line break inserted
- (x:float) (y:float) iters =
- let newx = x * x + xCoord - y * y
- let newy = 2.0 * x * y + yCoord
- match newx, newy, iters with
- | _ when Math.Abs newx > 2.0 -> iters
- | _ when Math.Abs newy > 2.0 -> iters
- | _ when iters = maxIterations -> iters
- | _ -> CalcZHelper xCoord yCoord newx newy (iters + 1)
- CalcZHelper (fst coord) (snd coord) (fst coord) (snd coord) 0
- let colorArray = Array.init 256 (fun i -> [|byte i;byte i;byte i;255uy|])
- let xDim = 1920
- let yDim = 1200
- let scale = 1./500.
- let conv (x,y) =
- (float (x - xDim / 2 - (xDim / 4))) * scale
- ,(float (y - yDim / 2)) * scale
- // Append this code with one of the following...
- // Fast version:
- let screen =
- Array.init (xDim*yDim) (fun i -> CalcZ <| conv (i % xDim, i / xDim))
- |> Array.collect (fun i -> colorArray.[i])
- let gch = GCHandle.Alloc(screen, GCHandleType.Pinned)
- let bmp = new Bitmap(xDim, yDim, xDim * 4, PixelFormat.Format32bppArgb, gch.AddrOfPinnedObject())
- gch.Free()
- bmp.Save(@"C:\Documents and Settings\All Users\Desktop\out.png")
- // Low memory version:
- let screen =
- Seq.init (xDim*yDim) (fun i -> CalcZ <| conv (i % xDim, i / xDim))
- |> Seq.collect (fun i -> colorArray.[i])
- |> Seq.toArray
- let gch = GCHandle.Alloc(screen, GCHandleType.Pinned)
- let bmp = new Bitmap(xDim, yDim, xDim * 4, PixelFormat.Format32bppArgb, gch.AddrOfPinnedObject())
- gch.Free()
- bmp.Save(@"C:\Documents and Settings\All Users\Desktop\out.png")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement