1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Posted at

研究室の先輩が作ったプログラム言語Mokkosuで
マンデルブロ集合を描画するプログラムを作りました。

#スクリーンショット
![mandel.png]
(https://qiita-image-store.s3.amazonaws.com/0/70577/7e3b31ae-2435-18c4-3125-e72f1338bb23.png)

#ソースコード

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";
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?