open System let rec rpt n f = if n = 0 then id else f >> (rpt (n-1) f) type Complex = { Re : float Im : float } let cm (a:Complex) (b:Complex) = { Re = (a.Re * b.Re - a.Im * b.Im); Im = (a.Re*b.Im + a.Im*b.Re)} let cp (a:Complex) (b:Complex) = { Re = (a.Re + b.Re); Im = (a.Im + b.Im)} let absComplex (a:Complex) : float = sqrt ( a.Re * a.Re + a.Im * a.Im) let mandelf (c: Complex) (z:Complex) = cp (cm z z) c let isMandel c = absComplex(rpt 20 (mandelf c) ({Re = 0.; Im=0.})) < 1.0 let scale (x:float, y:float) (u,v) n = float(n-u)/float(v-u) * (y-x) + x for i = 1 to 60 do for j = 1 to 60 do let lscale = scale (-1.2, 1.2) (1,60) in let t = {Re = lscale j; Im = lscale i} in Console.Write(if isMandel t then "*" else " ") Console.WriteLine("") open System.Drawing open System.Windows.Forms let form = let image = new Bitmap(400,400) let lscale = scale (-1.2, 1.2) (0,image.Height - 1) for i = 0 to image.Height - 1 do for j = 1 to image.Width - 1 do let t = {Re = lscale j; Im = lscale i} image.SetPixel(i,j, if isMandel t then Color.LightGoldenrodYellow else Color.Orange) image.Save(@"fs.png") let temp = new Form( Height = image.Height, Width = image.Width) temp.Paint.Add (fun e -> e.Graphics.DrawImage(image,0,0)) temp [<STAThread>] do Application.Run(form)

Комментарии
Отправить комментарий