研究室の先輩が作ったプログラム言語Mokkosuで
グモウスキー・ミラ写像を描画するプログラムを作りました。
#ソースコード
include "Graphics.mok";
#x(n+1) = y(n) + a(1-b y(n)^2)y(n) + f(x(n))
#y(n+1) = -x(n) + f(x(n+1))
#f(x) = mu x + 2(1-mu)x^2/(1+x^2)
let window_size = 500;
let x0 = 0.1;
let y0 = 0.1;
let a = 0.008;
let b = 0.05;
let mu = ~-.0.496;
let m = 11.5;
let iteration = 100000;
let calc_gumowski xpr ypr =
let f x = mu *. x +. 2.0 *. (1.0 -. mu)*. x *.x /. (1.0 +. x *. x) in
let xn x y = y +. a *. (1.0 -. b *. y *. y)*.y +. (f x) in
let yn x xn = ~-.x +. (f xn) in
let x = xn xpr ypr in
let y = yn xpr x in
(x, y);
let draw_gumowski gr =
fun loop xpr ypr n =
if n > iteration -> () else
let (x, y) = calc_gumowski xpr ypr in
let distance = pow (x *. x +. y *. y) 0.5 *. m in
let draw_x = double_to_int (x *. m) + window_size / 2 in
let draw_y = double_to_int (y *. m) + window_size / 2 in
let color_m = distance /. (int_to_double (window_size / 2)) in
let h = if color_m > 1.0 -> 360.0 else 360.0 *. color_m in
let (r,g,b) = hsv_to_rgb h 0.6 0.9 in
do draw_pixel gr r g b draw_x draw_y in
loop x y (n + 1)
in
loop x0 y0 1;
do scene "main" {
~Draw(gr) -> do
draw_gumowski gr;
end;
_ -> ();
};
do set_size window_size window_size;
do show_window "main";