on master help sign in
Rename Form to Collage. Add the LineStyle module.
ea4fe54evancz
core/Graphics/Collage.elmnew file+64
@@ -0,0 +1,64 @@
1+
2+module Graphics.Collage where
3+
4+import Either
5+import Graphics.LineStyle
6+import Geometry
7+
8+data Transform
9+ = Rotate Float
10+ | Move Float Float
11+ | Scale Float Float
12+ | Transform Float Float Float Float Float Float
13+
14+type Form = { transforms : [Transform], form : BasicForm }
15+
16+data FillStyle
17+ = NoFill
18+ | Solid Color
19+ | Texture String
20+ | Gradient Gradient
21+
22+data BasicForm
23+ = FLine LineStyle Line
24+ | FShape (Either LineStyle FillStyle) Shape
25+ | FImage Int Int (Int,Int) String
26+ | FElement Element
27+ | FGroup [Form]
28+
29+fill style shape = Form [] (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 = Form [] (FShape (Left style) shape)
41+trace style line = Form [] (FLine style line)
42+
43+sprite w h pos src = Form [] (FImage w h pos src)
44+toForm e = Form [] (FElement e)
45+
46+group fs = Form [] (FGroup fs)
47+
48+add t f = { transforms = t :: f.transforms, form = f.form }
49+
50+radians t = t
51+degrees dep = pi * deg / 180
52+rotations rot = 2 * pi * rot
53+
54+rotate t = add (Rotate t)
55+
56+scale s = add (Scale s s)
57+scaleX s = add (Scale s 1)
58+scaleY s = add (Scale 1 s)
59+
60+move x y = add (Move x y)
61+moveX x = add (Move x 0)
62+moveY y = add (Move 0 y)
63+
64+transform a b c d e f = add (Transform a b c d e f)
core/Graphics/Form.elmdeleted−85
@@ -1,85 +0,0 @@
1−
2−module Graphics.Collage where
3−
4−import Either
5−import Graphics.LineStyle
6−import Geometry
7−
8−data Transform
9− = Rotate Float
10− | Move Float Float
11− | Scale Float Float
12− | Transform Float Float Float Float Float Float
13−
14−data Form = Form [Transform] BasicForm
15−
16−data FillStyle
17− = NoFill
18− | Solid Color
19− | Texture String
20− | Gradient Gradient
21−
22−data BasicForm
23− = FLine LineStyle Line
24− | FShape (Either LineStyle FillStyle) Shape
25− | FImage Int Int Int Int String
26− | FElement Element
27− | FGroup [Form]
28−
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−
43−
44−linearGradient stops start end = setFillStyle (LinearGradient stops start end)
45−radialGradient stops innerP innerR outerP outerR =
46− setStyle (RadialGradient stops innerP innerR outerP outerR)
47−
48−plain = { width=1, cap=Butt, join=Miter, miterLimit=10,
49− fillStyle=...,
50− dashing=[], dashOffset=0 }
51−
52−solid c = Form [] . FLine c
53−dotted c = Form [] . FLine c
54−dashed c = Form [] . FLine c
55−lineStyle = Form [] . FLine
56−
57−
58−filled clr shp = Form [] (FShape shp)
59−outlined clr shp = Form [] (FShape shp)
60−customOutline pattern clr (Shape ps pos) =
61− Form [] (FShape (CustomOutline pattern) clr (Shape ps pos))
62−textured src (Shape ps pos) = Form [] (FShape (Textured src) black (Shape ps pos))
63−
64−fromLine = FLine
65−fromShape = FShape
66−fromElement = FElement
67−
68−sprite w h pos src = Form 0 1 pos (FImage w h src)
69−toForm pos e = Form 0 1 pos (FElement e)
70−
71−addTransform t (Form ts form) = Form (t:ts) form
72−
73−rotateRad rad = addTransform $ Rotate rad
74−rotateDeg deg = addTransform $ Rotate (pi * deg / 180)
75−rotate rot = addTransform $ Rotate (2 * pi * rot)
76−
77−scale s = addTransform (Scale s s)
78−scaleX s = addTransform (Scale s 1)
79−scaleY s = addTransform (Scale 1 s)
80−
81−move x y = addTransform (Move x y)
82−moveX x = addTransform (Move x 0)
83−moveY y = addTransform (Move 0 y)
84−
85−transform a b c d e f = addTransform (Transform a b c d e f)
core/Graphics/LineStyle.elmnew file+31
@@ -0,0 +1,31 @@
1+
2+module Graphics.LineStyle where
3+
4+import Graphics.Color
5+
6+data LineCap = Butt | Round | Square
7+data LineJoin = Round | Bevel | Miter
8+
9+type LineStyle = {
10+ color : Color,
11+ width : Float,
12+ cap : LineCap,
13+ join : LineJoin,
14+ miterLimit : Float,
15+ dashing : [Int],
16+ dashOffset : Int
17+ }
18+
19+default = {
20+ color = black,
21+ width = 1,
22+ cap = Butt,
23+ join = Miter,
24+ dashing = [],
25+ dashOffset = 0,
26+ miterLimit = 10
27+ }
28+
29+solid clr = { default | color <- clr }
30+dashed clr = { default | color <- clr, dashing = [8,4] }
31+dotted clr = { default | color <- clr, dashing = [3,3] }