@@ -1,25 +1,9 @@
11
2−module Collage where
2+module Graphics.Collage where
33
4−data Path = Path [(Float,Float)]
5−
6−path = Path
7−segment p1 p2 = Path [p1,p2]
8−
9−data Shape = Shape [(Float,Float)]
10−
11−polygon = Shape
12−
13−rect w h = polygon [ (0-w/2,0-h/2), (0-w/2,h/2), (w/2,h/2), (w/2,0-h/2) ]
14−oval w h =
15− let n = 50
16− f i = (w/2 * cos (2*pi/n * i), h/2 * sin (2*pi/n * i))
17− in Shape $ map f [0..n-1]
18−circle r = oval (2*r) (2*r)
19−ngon n r =
20− let m = toFloat n
21− f i = ( r * cos (2*pi/m * i), r * sin (2*pi/m * i))
22− in Shape $ map f [0..n-1]
4+import Either
5+import Graphics.LineStyle
6+import Geometry
237
248data Transform
259 = Rotate Float
@@ -29,47 +13,37 @@ data Transform
2913
3014data Form = Form [Transform] BasicForm
3115
32−
33−data LineCap = Butt | Round | Square
34−data LineJoin = Round | Bevel | Miter
35−
3616data FillStyle
3717 = NoFill
3818 | Solid Color
3919 | Texture String
40− | LinearGradient [(Float,Color)] (Float,Float) (Float,Float)
41− | RadialGradient [(Float,Color)] (Float,Float) Float (Float,Float) Float
42−
43−-- dash pattern, dash offset, line width, cap, join, miter limit, fill style
44−type LineStyle = {
45− width : Float,
46− cap : LineCap,
47− join : LineJoin,
48− miterLimit : Float,
49− fillStyle : FillStyle,
50− dashing : [Int],
51− dashOffset : Int
52−}
20+ | Gradient Gradient
5321
5422data BasicForm
5523 = FLine LineStyle Line
56− | FShape LineStyle FillStyle Shape
24+ | FShape (Either LineStyle FillStyle) Shape
5725 | FImage Int Int Int Int String
5826 | FElement Element
5927 | FGroup [Form]
6028
61−setFillStyle fs form =
62− case form of
63− FLine ls _ ln -> FLine ls fs ln
64− FShape ls _ shp -> FLine ls fs shp
65− _ -> form
29+fill style shape = FShape (Right style) shape
30+
31+filled : Color -> Shape -> Form
32+filled color shape = fill (Solid color) shape
33+
34+textured : String -> Shape -> Form
35+textured src shape = fill (Texture src) shape
36+
37+gradient : Gradient -> Shape -> Form
38+gradient grad shape = fill (Gradient grad) shape
39+
40+outline style shape = FShape (Left style) shape
41+trace = FLine
42+
6643
67−noFill = setFillStyle NoFill
68−fillColor clr = setFillStyle (Solid clr)
69−texture src = setFillStyle (Texture src)
7044linearGradient stops start end = setFillStyle (LinearGradient stops start end)
7145radialGradient stops innerP innerR outerP outerR =
72− setFillStyle (RadialGradient stops innerP innerR outerP outerR)
46+ setStyle (RadialGradient stops innerP innerR outerP outerR)
7347
7448plain = { width=1, cap=Butt, join=Miter, miterLimit=10,
7549 fillStyle=...,