Skip to content

Instantly share code, notes, and snippets.

@fetburner
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save fetburner/a43859f7cf97f9206c57 to your computer and use it in GitHub Desktop.

Select an option

Save fetburner/a43859f7cf97f9206c57 to your computer and use it in GitHub Desktop.
マンデルブロ集合描くやつ
#load "graphics.cma";;
let ( @. ) f g x = f (g x)
let rec natural acc = function
| 0 -> acc
| n -> natural (n :: acc) (n - 1)
let natural = natural []
let complex_of_pos (x, y) =
(-1.5 +. float_of_int x *. 2. /. float_of_int (Graphics.size_x ()),
-1. +. float_of_int y *. 2. /. float_of_int (Graphics.size_y ()))
let rec is_mandel (re_z, im_z) n (re_c, im_c) =
if n = 0 then true
else if re_z *. re_z +. im_z *. im_z > 4. then false
else is_mandel
(re_z *. re_z -. im_z *. im_z +. re_c, 2. *. re_z *. im_z +. im_c)
(n - 1)
(re_c, im_c)
let is_mandel = is_mandel (0., 0.)
let () =
Graphics.open_graph "";
Graphics.resize_window 500 500;
natural (Graphics.size_y ())
|> List.map (fun i ->
natural (Graphics.size_x ())
|> List.map (fun j -> (i, j)))
|> List.flatten
|> List.filter (is_mandel 100 @. complex_of_pos)
|> List.iter (fun (x, y) -> Graphics.plot x y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment