let sq3=sqrt 3. and sq5=sqrt 5. and sq2=sqrt 2. and pi=3.14159265358979323846264;; let l=2.;; let a=l *. sqrt (2. /. (5.-.sq5)) let (* расстояние от вершины до центра в пятиугольнике *) h=l /. 2. *. sqrt ((3. +. sq5) /. (5. -. sq5)) let (* высота из цетра на сторону пятиугольника *) r=l /. 4. *. sqrt (10. +. 22. /. sq5) let (* радиус вписанной окружности *) ro=l/. 4. *. (1. +. sq5) *. sq3 let cos72=(sq5 -. 1.) /. 2. let sin72=(sqrt (5. +. sq5)) /. (2. *. sq2) let sin36=(sqrt (5. -. sq5)) /. (2. *. sq2) let cos36=(sq5 +. 1.) /. 4. let alpha=pi -. 2. *. asin (r /. ro) let z=a +. l *. cos alpha ;; let verts_down=[ (0. , -. r , -. a) ; ( -. a *. sin72, -. r , a *. ( -. 1. +. cos72)) ; (-. a *. sin36, -. r , h ) ; ( a *. sin36, -.r , h ) ; ( a *. sin72, -. r , a *. ( -. 1. +. cos72)); ( 0. , l*. (sin alpha) -. r , -. z); ( -. z *. sin72 , l*. (sin alpha) -. r, -. z +. z *. cos72); (-. z *. sin36 , l*. (sin alpha) -. r , z *. cos36); (z *. sin36 , l*. (sin alpha) -. r , z *. cos36); ( z *. sin72 , l*. (sin alpha) -. r, -. z +. z *. cos72); ];; let verts_up= let rec vu l= match l with (a,b,c)::ls->(-. a, -. b, -. c)::(vu ls) |[]->[] in List.rev (vu verts_down);; let vertices=verts_down @ verts_up;; let faces=[[0;1;2;3;4];[2;7;14;8;3];[3;8;13;9;4];[0;4;9;12;5];[0;5;11;6;1];[1;6;10;7;2]; [15;16;17;18;19];[7;10;15;19;14];[8;14;19;18;13];[9;13;18;17;12];[5;12;17;16;11];[6;11;16;15;10]];; let color= Random.self_init (); let rec help i l= if i>0 then help (i-1) (((Random.float 0.9)+. 0.1,(Random.float 0.9)+. 0.1,(Random.float 0.9)+. 0.1)::l) else l in help 12 [];; let nothing ()= ();; let display () = GlClear.color (0., 0., 0.); (* цвет фона *) GlClear.clear [`color; `depth]; (* типа clear_graph () *) (* GlDraw.color (0.3, 0.5, 0.7); GlDraw.begins `polygon; GlDraw.vertex3 (-3.0, 3.0, 3.0); GlDraw.vertex3 (-3.0, -3.0, 3.0); GlDraw.vertex3 ( 3.0, -3.0, 3.0); GlDraw.vertex3 ( 3.0, 3.0, 3.0); GlDraw.ends ();*) List.iter2 (fun face color -> GlDraw.color ~alpha:0. color; (* установка цвета рисования *) GlDraw.begins `polygon; (* рисуем полигон *) List.iter (fun i -> GlDraw.vertex3 (List.nth vertices i); nothing ()) face; GlDraw.ends (); ) faces color; Gl.flush (); Glut.swapBuffers ();; let keyboard ~key ~x ~y = match key with | 27 -> exit 0 | 97 -> GlMat.rotate ~angle: (-. 2.0) ~x:1.0 (); display () | 115 -> GlMat.rotate ~angle:2.0 ~y:1.0 (); display () | 100 -> GlMat.rotate ~angle:2.0 ~z:1.0 (); display () | _ -> ();; let main ()= ignore(Glut.init Sys.argv); Glut.initDisplayMode ~alpha:true ~depth:true () ; Glut.initWindowSize ~w:600 ~h:600 ; ignore(Glut.createWindow ~title:"Dodecahedron"); GlMat.ortho ~x:(-4.0,4.0) ~y:(-4.0,4.0) ~z:(-4.0,4.0); GlDraw.cull_face `back; Gl.enable `cull_face; Gl.enable `blend; Glut.displayFunc ~cb:display; Glut.keyboardFunc ~cb:keyboard; Glut.mainLoop (); ;; main ();;