Help us understand the problem. What is going on with this article?

# Mokkosuでマンデルブロ集合を描画してみた

More than 5 years have passed since last update.

マンデルブロ集合を描画するプログラムを作りました。

# ソースコード

```include "Graphics.mok";

let window_size = 500;
let x = ~-. 0.740425 -. 0.3;
let y = 0.113265 +. 0.12;
let w = 0.5;
let iteration = 500;

let judge_mandel c =
fun loop z count =
if count > iteration -> ~- 1 else
if pow (fst z) 2.0 +. pow (snd z) 2.0 > 2.0 -> count else
let zr = pow (fst z) 2.0 -. pow (snd z) 2.0 +. fst c in
let zi = 2.0 *. (fst z) *. (snd z) +. snd c in
let next_z = (zr, zi) in
loop (next_z) (count + 1)
in
loop (0.0, 0.0) 0;

let draw_mandel gr =
let h = window_size / 2 in
(for i <- ~-h .. h in
let cr = w *. (int_to_double i) /. (int_to_double h) +. x in
for j <- ~-h .. h in
let ci = w *. (int_to_double j) /. (int_to_double h) +. y in
let judge = judge_mandel (cr, ci) in
if (judge == ~- 1) -> ()
else
let color = 360.0 *. pow ((int_to_double judge) /. (int_to_double iteration)) 0.33 in
let h = color in
let s = 0.60 in
let v = 0.90 in
let pixel_x = window_size / 2 + i in
let pixel_y = window_size / 2 - j in
let (r, g, b) = hsv_to_rgb h s v in
draw_pixel gr r g b pixel_x pixel_y) |> ignore;

do scene "main" {
~Draw(gr) -> do
draw_mandel gr;
end;
_ -> ();
};

do set_size window_size window_size;

do show_window "main";
```
Why not register and get more from Qiita?
1. We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
2. you can read useful information later efficiently
By "stocking" the articles you like, you can search right away