open Graphics;;
open List;; let scalar a b =
fold_left (+.) (0.) (map2 ( *. ) a b);;
let mul_vm m v =
map (scalar v) m;;
let rotate_point_x x point =
mul_vm [[1.; 0.; 0.];[0.; cos x; -.(sin x)];[0.; sin x; cos x]] point;;
let rotate_point_y y point =
mul_vm [[cos y; 0.; sin y];[0.; 1.; 0.];[-.(sin y); 0.; cos y]] point;;
let rotate_point_z z point =
mul_vm [[cos z; -.(sin z); 0.];[sin z; cos z; 0.];[0.; 0.; 1.]] point;;
let rotate_point x y z point =
rotate_point_x x (rotate_point_y y (rotate_point_z z point));;
let rotate_graph x y z = map (rotate_point x y z);;
let stretch_point q = map (( *. ) q);;
let stretch_graph q = map (stretch_point q);;
let f x y = sin (x ** y);;
let gen_graph lowlim_x highlim_x lowlim_y highlim_y step_x step_y =
let rec gg cur_x cur_y =
if cur_x > highlim_x then [] else
if cur_y > highlim_y then gg (cur_x +. step_x) lowlim_y else
[cur_x; cur_y; f cur_x cur_y]::(gg cur_x (cur_y +. step_y))
in gg lowlim_x lowlim_y;;
let rec draw_graph points =
match points with
[] -> ()
|[x;y;_]::ls -> plot ((int_of_float x) + ((size_x ()) / 2)) ((int_of_float y) + ((size_y ()) / 2)); draw_graph ls
|_ -> failwith "Strange point";;
let rec render graph =
if not (key_pressed ()) then (clear_graph (); draw_graph graph; render (rotate_graph 0.02 0.01 0.03 graph));;
let sin_graph = stretch_graph 100. (gen_graph (0.01) 3. (0.01) 3. 0.05 0.05);;
open_graph "";;
render sin_graph;;
read_key ();;
close_graph ();;