1(* 2 Copyright 2008,2011 by Mark Weyer 3 Maintenance modifications 2010,2011 by the cuyo developers 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18*) 19 20open Farbe 21open Graphik 22open Vektorgraphik 23open Helfer 24 25open Male_mit_aa 26 27let male breite hoehe bild = 28 male bild (1.0/.32.0) (monochrom durchsichtig breite hoehe) 29 30let raus gric name bild = gib_xpm_aus (rgb_grau 1.0) name (berechne gric bild) 31 32let bogen (x,y) winkel laenge kruemmung = 33 let cw,sw = cos winkel, sin winkel in 34 let pos = kruemmung > 0.0 in 35 let w' = if pos then winkel-.pi/.2.0 else winkel+.pi/.2.0 in 36 Bogen ((x-.kruemmung*.sw,y+.kruemmung*.cw), 37 (if pos then kruemmung else -.kruemmung), 38 pos, w', w'+.laenge/.kruemmung) 39 40 41let arm_dicke1 = 1.0/.30.0 42let arm_dicke2 = 1.0/.45.0 43 44let octopus (a0,a1,a2,a3,a4,a5,a6,a7) farbe1 farbe2 = 45 let arm nummer kruemmung = 46 let winkel = (float_of_int (nummer+2))*.pi/.4.0 in 47 [match kruemmung with 48 | None -> Strecke ((0.5,0.5),(0.5+.cos winkel,0.5+.sin winkel)) 49 | Some r -> bogen (0.5,0.5) (winkel-.1.0/.7.0/.r) (3.0/.7.0) r 50 ] in 51 let arme = konvertiere_polygon 52 ((arm 0 a0) @ (arm 1 a1) @ (arm 2 a2) @ (arm 3 a3) @ 53 (arm 4 a4) @ (arm 5 a5) @ (arm 6 a6) @ (arm 7 a7)) in 54 let kopfrad = 1.0/.4.0 in 55 let kopfh = kopfrad*.3.0/.4.0 in 56 let halsy = 0.5-.kopfrad*.(2.0-.sqrt(3.0)) in 57 let kopfy = halsy+.kopfh in 58 let kopf = konvertiere_polygon [ 59 Bogen ((0.5,kopfy), kopfrad, true, 0.0, pi); 60 Strecke ((0.5-.kopfrad, kopfy), (0.5-.kopfrad, halsy)); 61 Bogen ((0.5, halsy+.kopfrad*.sqrt(3.0)), 2.0*.kopfrad, 62 true, pi*.4.0/.3.0, pi*.5.0/.3.0); 63 Strecke ((0.5+.kopfrad, halsy), (0.5+.kopfrad, kopfy)) 64 ] in 65 let blesse = konvertiere_polygon 66 [Bogen ((0.5,kopfy), kopfrad*.3.0/.4.0, true, 67 pi*.2.0/.5.0, pi*.3.0/.4.0)] in 68 let augerad = kopfrad/.3.0 in 69 let augey = kopfy in 70 let augend = augerad*.3.0 in 71 let puprad = kopfrad/.5.0 in 72 let pupy = augey-.puprad/.2.0 in 73 let augepup t = 74 let x = 0.5+.augend*.t/.2.0 in 75 [Kreis ((x,augey),augerad)], 76 [Kreis ((x,pupy),puprad)] in 77 let auge1,pup1 = augepup (-1.0) in 78 let auge2,pup2 = augepup (1.0) in 79 let auge = konvertiere_polygon (auge1@auge2) in 80 let pup = konvertiere_polygon (pup1@pup2) in 81 male 1 1 (erzeuge_vektorbild [ 82 Dicker_Strich (farbe1, 1.0/.30.0, [arme]); 83 Dicker_Strich (farbe2, 1.0/.45.0, [arme]); 84 Strich (farbe1, [kopf]); 85 Flaechen ([| farbe1; weiss; schwarz |], [ 86 kopf, 0, None; 87 auge, 1, Some 0; 88 pup, 2, Some 1; 89 ]); 90 Dicker_Strich (farbe2, kopfrad/.7.0, [blesse]); 91 ]) 92 93let octopus (k0,k1,k2,k3,k4,k5,k6,k7) ad a0 a2 a4 a6 = 94 octopus ( 95 (if a0 then None else Some k0), 96 (if ad then None else Some k1), 97 (if a2 then None else Some k2), 98 (if ad then None else Some k3), 99 (if a4 then None else Some k4), 100 (if ad then None else Some k5), 101 (if a6 then None else Some k6), 102 (if ad then None else Some k7)) 103 104let schema_mitte farbe1 farbe2 = 105 let raute = konvertiere_polygon [ 106 Strecke ((-0.5,0.5),(0.5,-0.5)); 107 Strecke ((0.5,-0.5),(1.5,0.5)); 108 Strecke ((1.5,0.5),(0.5,1.5)); 109 Strecke ((0.5,1.5),(-0.5,0.5)); 110 ] in 111 male 1 1 (erzeuge_vektorbild [ 112 Dicker_Strich (farbe1, arm_dicke1, [raute]); 113 Dicker_Strich (farbe2, arm_dicke2, [raute]); 114 ]) 115 116let octopi farbe1 farbe2 kruemmungen = 117 let octopus = octopus kruemmungen in 118 kombiniere_bildchen 3 3 119 (List.map (fun (x,y,b) -> (x,y,b farbe1 farbe2)) [ 120 0,0,octopus false true true false false; 121 1,0,octopus true false false true true; 122 2,0,octopus false false true true false; 123 0,1,octopus true false true true false; 124 1,1,schema_mitte; 125 2,1,octopus true true false false true; 126 0,2,octopus false true false false true; 127 1,2,octopus true true true false false; 128 2,2,octopus false false false true true; 129 ]) 130 131let octopi_daten = [| 132 rgbrgb 0.79 0.06 0.79, rgbrgb 0.95 0.37 0.96, 133 ( 3.0, -1.0, 0.5, 1.5, -0.3, -2.0, 0.4, 0.7); 134 rgb_grau 0.2, rgb_grau 0.6, 135 (-2.0, -1.5, -1.5, 0.8, 1.0, -1.0, 0.6, -1.0); 136 rgbrgb 0.2 0.2 0.8, rgbrgb 0.5 0.5 1.0, 137 (-2.5, 1.0, 0.7, -0.5, -0.5, 0.6, -1.0, 1.5); 138 rgbrgb 0.6 0.61 0.1, rgbrgb 0.8 0.83 0.3, 139 ( 3.0, 0.7, 1.0, -0.3, 0.8, 0.3, -2.0, -1.0); 140 rgbrgb 0.8 0.5 0.1, rgbrgb 0.9 0.7 0.4, 141 ( 2.0, 1.5, -0.3, -1.0, -2.0, 0.5, 1.0, 1.0); 142 |] 143 144let octopi gric command outname = 145 let nummer = int_of_string (suffix command 1) - 1 in 146 let farbe1,farbe2,kruemmungen = octopi_daten.(nummer) in 147 raus gric outname (octopi (von_rgb farbe1) (von_rgb farbe2) kruemmungen) 148 149 150 151let welle w d x y = cos ((x*.cos w +. y*.sin w)/.d) 152 153let anemone w1 w2 = 154 let num = 50 in 155 let g = (sqrt 5.0 -. 1.0)*.pi in 156 let num_ = float_of_int num in 157 let farbe1 = von_rgb (rgbrgb 1.0 0.7 0.7) in 158 let farbe2 = von_rgb (rgbrgb 1.0 0.3 0.7) in 159 let farbe3 = von_rgb (rgbrgb 1.0 1.0 0.7) in 160 let farbe4 = von_rgb (rgbrgb 0.8 0.8 0.2) in 161 let faeden = Array.init num 162 (fun i -> 163 let i = float_of_int i in 164 let w = g *. i in 165 let r = sqrt (i/.num_)/.4.0 in 166 (r*.cos w, r*.sin w)) in 167 Array.sort 168 (fun (x1,y1) -> fun (x2,y2) -> Pervasives.compare y2 y1) 169 faeden; 170 male 1 1 (erzeuge_vektorbild (List.concat (List.map 171 (fun (x,y) -> 172 let r2 = x*.x +. y*.y in 173 let mitte = 31.0*.r2 < 1.0 in 174 let strich = konvertiere_polygon 175 [bogen (0.5+.x, 0.25+.y/.2.0) (pi/.2.0 -. x) 176 ((if mitte then 0.3 else 0.4) 177 -. 3.0*.r2 +. (welle w1 0.1 x y)/.29.0 +. y/.3.0) 178 (0.4/.((welle w2 0.1 x y)/.2.0 -. 5.0*.x))] in 179 [Dicker_Strich ((if mitte then farbe4 else farbe2), 180 1.0/.29.0, [strich]); 181 Strich ((if mitte then farbe3 else farbe1), [strich]); 182 ]) 183 (Array.to_list faeden)))) 184 185let anemonen gric outname = 186 raus gric outname (kombiniere_bildchen 4 1 187 (List.map (fun (x,w1,w2) -> (x,0,anemone w1 w2)) [ 188 0, 4.0, 1.0; 189 1, 8.0, 6.0; 190 2, 7.0, 5.0; 191 3, 2.0, 3.0; 192 ])) 193 194 195let fisch gric outname = 196 let blau1 = von_rgb (rgbrgb 0.45 0.55 1.0) in 197 let blau2 = von_rgb (rgbrgb 0.5 0.7 1.0) in 198 let blau3 = von_rgb (rgbrgb 0.3 0.4 0.8) in 199 let koerper_p = (0.55,0.5) in 200 let koerper = konvertiere_polygon [Kreis (koerper_p,0.35)] in 201 let auge_p = (0.75,0.6) in 202 let dreieck p1 p2 p3 = konvertiere_polygon 203 [Strecke (p1,p2); Strecke (p2,p3); Strecke (p3,p1)] in 204 let ruecken = dreieck (0.5,0.9) (0.6,0.8) (0.5,0.8) in 205 let schwanz = dreieck (0.2,0.5) (0.1,0.7) (0.1,0.3) in 206 let bein = dreieck (0.35,0.25) (0.35,0.15) (0.4,0.2) in 207 let arm = dreieck (0.7,0.25) (0.75,0.15) (0.75,0.3) in 208 let flosse umriss = 209 [Strich (blau3,[umriss]); Flaechen ([| blau3 |],[umriss,0,None])] in 210 let fisch = 211 (flosse ruecken) @ (flosse schwanz) @ (flosse bein) @ 212 [ 213 Strich (blau1,[koerper]); 214 Flaechen ([| blau1; weiss; schwarz |], [ 215 koerper,0,None; 216 konvertiere_polygon [Kreis (auge_p,0.09)], 1, Some 0; 217 konvertiere_polygon [Kreis (auge_p,0.03)], 2, Some 1; 218 ]); 219 Dicker_Strich (blau2, 0.04, [konvertiere_polygon 220 [Bogen (koerper_p,0.25,true,pi*.2.0/.5.0, pi*.6.0/.7.0)]]) 221 ] @ 222 (flosse arm) in 223 raus gric outname (male 1 1 (erzeuge_vektorbild fisch)) 224 225 226;; 227 228let gric,command,outname = Gen_common.parse_args () in 229 230match command with 231| "moAnemone" -> anemonen gric outname 232| "moFisch" -> fisch gric outname 233| _ -> octopi gric command outname 234 235