let x = 0.525731112119133606 let z = 0.850650808352039932 let vertices = [(-.x, 0.0, z); ( x, 0.0, z); (-.x, 0.0, -.z); ( x, 0.0, -.z); (0.0, z, x); (0.0, z, -.x); (0.0, -.z, x); (0.0, -.z, -.x); ( z, x, 0.0); (-.z, x, 0.0); ( z, -.x, 0.0); (-.z, -.x, 0.0);] let faces = [[0; 4; 1]; [0; 9; 4]; [9; 5; 4]; [4 ; 5; 8]; [4; 8; 1]; [8; 10; 1]; [8; 3; 10]; [5; 3; 8]; [5 ; 2; 3]; [2; 7; 3]; [7; 10; 3]; [7; 6; 10]; [7; 11; 6]; [11; 0; 6]; [0; 1; 6]; [6; 1; 10]; [9; 0; 11]; [9; 11; 2]; [9 ; 2; 5]; [7; 2; 11];] let color = Array.to_list (Array.init 20 (fun _ -> Random.float 1.0, Random.float 1.0, Random.float 1.0)) let display () = GlClear.clear [`color; `depth]; (* типа clear_graph () *) List.iter2 (fun face color -> GlDraw.color color; (* установка цвета рисования *) GlDraw.begins `triangles; List.iter (fun i -> GlDraw.vertex3 (List.nth vertices i)) face; GlDraw.ends (); ) faces color; Gl.flush (); Glut.swapBuffers ();; let keyboard ~key ~x ~y = match key with | 27 -> exit 0 | 49 -> GlMat.rotate ~angle:2.0 ~x:1.0 (); display () | 50 -> GlMat.rotate ~angle:2.0 ~y:1.0 (); display () | 51 -> GlMat.rotate ~angle:2.0 ~z:1.0 (); display () | _ -> Printf.printf "Unknown key: %d" key;; let main () = ignore(Glut.init Sys.argv); Glut.initDisplayMode ~alpha:true ~depth:true () ; Glut.initWindowSize ~w:500 ~h:500 ; ignore(Glut.createWindow ~title:"Icosahedron"); GlMat.ortho ~x:(-1.1, 1.1) ~y:(-1.1, 1.1) ~z:(-1.1, 1.1); GlDraw.cull_face `back; Gl.enable `cull_face; Gl.enable `blend; Gl.enable `depth_test; GlClear.color (0.5, 0.5, 0.5); (* цвет фона *) Glut.displayFunc ~cb:display; Glut.keyboardFunc ~cb:keyboard; Glut.mainLoop (); ;; main ();;