on master help sign in
Get rid of the FillStyle module. Move gradients to Color and everything else to Form.
71f83d3evancz
core/Geometry.elmnew file+28
@@ -0,0 +1,28 @@
1+-- Paths and Shapes.
2+-- These structures are purely geometric forms, no colors or styles.
3+-- Could be the basis of some cool geometry stuff :)
4+
5+module Geometry where
6+
7+data Path = Path [(Float,Float)]
8+
9+path = Path
10+segment p1 p2 = Path [p1,p2]
11+
12+type Shape = [(Float,Float)]
13+
14+polygon points = points
15+
16+rect w h = [ (0-w/2,0-h/2), (0-w/2,h/2), (w/2,h/2), (w/2,0-h/2) ]
17+
18+oval w h =
19+ let n = 50
20+ f i = (w/2 * cos (2*pi/n * i), h/2 * sin (2*pi/n * i))
21+ in map f [0..n-1]
22+
23+circle r = oval (2*r) (2*r)
24+
25+ngon n r =
26+ let m = toFloat n
27+ f i = ( r * cos (2*pi/m * i), r * sin (2*pi/m * i))
28+ in map f [0..n-1]
core/Graphics/Color.elm+6−1
@@ -41,4 +41,9 @@ violet = Color 238 130 238 1
41
41
42complement = C.complement
42complement = C.complement
43hsva = C.hsva
43hsva = C.hsva
44−hsv = C.hsv
44+hsv = C.hsv
45+
46+data Gradient
47+ = Linear [(Float,Color)] (Float,Float) (Float,Float)
48+ | Radial [(Float,Color)] (Float,Float) Float (Float,Float) Float
49+
core/Graphics/FillStyle.elmdeleted−2
@@ -1,2 +0,0 @@
1−
2−module FillStyle where
core/Graphics/Form.elm+21−47
@@ -1,25 +1,9 @@
1
1
2−module Collage where
2+module Graphics.Collage where
3
3
4−data Path = Path [(Float,Float)]
4+import Either
5−
5+import Graphics.LineStyle
6−path = Path
6+import Geometry
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]
23
7
24data Transform
8data Transform
25 = Rotate Float
9 = Rotate Float
@@ -29,47 +13,37 @@ data Transform
29
13
30data Form = Form [Transform] BasicForm
14data Form = Form [Transform] BasicForm
31
15
32−
33−data LineCap = Butt | Round | Square
34−data LineJoin = Round | Bevel | Miter
35−
36data FillStyle
16data FillStyle
37 = NoFill
17 = NoFill
38 | Solid Color
18 | Solid Color
39 | Texture String
19 | Texture String
40− | LinearGradient [(Float,Color)] (Float,Float) (Float,Float)
20+ | Gradient Gradient
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−}
53
21
54data BasicForm
22data BasicForm
55 = FLine LineStyle Line
23 = FLine LineStyle Line
56− | FShape LineStyle FillStyle Shape
24+ | FShape (Either LineStyle FillStyle) Shape
57 | FImage Int Int Int Int String
25 | FImage Int Int Int Int String
58 | FElement Element
26 | FElement Element
59 | FGroup [Form]
27 | FGroup [Form]
60
28
61−setFillStyle fs form =
29+fill style shape = FShape (Right style) shape
62− case form of
30+
63− FLine ls _ ln -> FLine ls fs ln
31+filled : Color -> Shape -> Form
64− FShape ls _ shp -> FLine ls fs shp
32+filled color shape = fill (Solid color) shape
65− _ -> form
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+
66
43
67−noFill = setFillStyle NoFill
68−fillColor clr = setFillStyle (Solid clr)
69−texture src = setFillStyle (Texture src)
70linearGradient stops start end = setFillStyle (LinearGradient stops start end)
44linearGradient stops start end = setFillStyle (LinearGradient stops start end)
71radialGradient stops innerP innerR outerP outerR =
45radialGradient stops innerP innerR outerP outerR =
72− setFillStyle (RadialGradient stops innerP innerR outerP outerR)
46+ setStyle (RadialGradient stops innerP innerR outerP outerR)
73
47
74plain = { width=1, cap=Butt, join=Miter, miterLimit=10,
48plain = { width=1, cap=Butt, join=Miter, miterLimit=10,
75 fillStyle=...,
49 fillStyle=...,