on master help sign in
Get rid of the FillStyle module. Move gradients to Color and everything else to Form.

Create the Geometry module which describes paths and shapes. Not sure if this module is a good idea.

commit71f83d394e65443f11e65b21da7f7f4aedce8f4e authorevancz <info@elm-lang.org> dateTue 5 Mar 2013, 19:46 (14 years ago) parent0fbfab7
4 files changed+55−50
core/Geometry.elm+28 core/Graphics/Color.elm+6−1 core/Graphics/FillStyle.elm−2 core/Graphics/Form.elm+21−47
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
4141
4242complement = C.complement
4343hsva = 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 @@
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=...,