on 9c8dfd9 help sign in
elk/libraries/Graphics/Collage.elm
98 lines 2.2 kB history raw
2module Graphics.Collage where
4import Either
5import Graphics.Geometry
6import Native.Graphics.Matrix as Matrix
7import Native.Graphics.Collage as N
8import Graphics.Element
9import Graphics.Color as Color
11type Form = {
12 theta : Float,
13 scale : Float,
14 x : Float,
15 y : Float,
16 form : BasicForm
17 }
19data FillStyle
20 = Solid Color
21 | Texture String
22 | Gradient Gradient
24data LineCap = Butt | Round | Square
25data LineJoin = Smooth | Sharp | Clipped
27type LineStyle = {
28 color : Color,
29 width : Float,
30 cap : LineCap,
31 join : LineJoin,
32 miterLimit : Float,
33 dashing : [Int],
34 dashOffset : Int
35 }
37defaultLine = {
38 color = Color.black,
39 width = 1,
40 cap = Butt,
41 join = Sharp,
42 dashing = [],
43 dashOffset = 0,
44 miterLimit = 10
45 }
47solid clr = { defaultLine | color <- clr }
48dashed clr = { defaultLine | color <- clr, dashing <- [8,4] }
49dotted clr = { defaultLine | color <- clr, dashing <- [3,3] }
51data BasicForm
52 = FPath LineStyle Path
53 | FShape (Either LineStyle FillStyle) Shape
54 | FImage Int Int (Int,Int) String
55 | FElement Element
56 | FGroup Matrix [Form]
58form f = { theta = 0, scale = 1, x = 0, y = 0, form = f }
60fill style shape = form (FShape (Right style) shape)
62filled : Color -> Shape -> Form
63filled color shape = fill (Solid color) shape
65textured : String -> Shape -> Form
66textured src shape = fill (Texture src) shape
68gradient : Gradient -> Shape -> Form
69gradient grad shape = fill (Gradient grad) shape
71outlined : LineStyle -> Shape -> Form
72outlined style shape = form (FShape (Left style) shape)
74traced : LineStyle -> Path -> Form
75traced style path = form (FPath style path)
77sprite : Int -> Int -> (Int,Int) -> String -> Form
78sprite w h pos src = form (FImage w h pos src)
80toForm : Element -> Form
81toForm e = form (FElement e)
83group : [Form] -> Form
84group fs = form (FGroup Matrix.identity fs)
86groupTransform : Matrix -> [Form] -> Form
87groupTransform matrix fs = form (FGroup matrix fs)
89rotate : Float -> Form -> Form
90rotate t f = { f | theta <- f.theta + t }
92scale s f = { f | scale <- f.scale * s }
94move x y f = { f | x <- f.x + x, y <- f.y + y }
95moveX x f = { f | x <- f.x + x }
96moveY y f = { f | y <- f.y + y }
98collage : Int -> Int -> [Form] -> Element