@@ -22,35 +22,49 @@ data FillStyle
22 | Texture String
22 | Texture String
23 | Gradient Gradient
23 | Gradient Gradient
25+-- The shape of the ends of a line.
25−data LineCap = Butt | Round | Square
26+data LineCap = Flat | Round | Padded
26−data LineJoin = Smooth | Sharp | Clipped
28+-- The shape of the “joints” of a line, where each line segment
29+-- meets. `Sharp` takes an argument to limit the length of the joint. This
31+data LineJoin = Smooth | Sharp Float | Clipped
33+-- All of the attributes of a line style. This lets you build up a line style
34+-- however you want. You can also update existing line styles with record updates.
28type LineStyle = {
35type LineStyle = {
29 color : Color,
36 color : Color,
30 width : Float,
37 width : Float,
31 cap : LineCap,
38 cap : LineCap,
32 join : LineJoin,
39 join : LineJoin,
34 dashing : [Int],
40 dashing : [Int],
35 dashOffset : Int
41 dashOffset : Int
44+-- The default line style, which is solid black with flat caps and sharp joints.
45+-- You can use record updates to build the line style you
46+-- want. For example, to make a thicker line, you could say:
48+-- { defaultLine | width <- 10 }
38defaultLine : LineStyle
49defaultLine : LineStyle
39defaultLine = {
50defaultLine = {
40 color = Color.black,
51 color = Color.black,
41 width = 1,
52 width = 1,
42− cap = Butt,
53+ cap = Flat,
43− join = Sharp,
54+ join = Sharp 10,
44 dashing = [],
55 dashing = [],
45 dashOffset = 0,
56 dashOffset = 0,
49−-- default LineStyles
59+-- Create a solid line style with a given color.
50solid : Color -> LineStyle
60solid : Color -> LineStyle
51solid clr = { defaultLine | color <- clr }
61solid clr = { defaultLine | color <- clr }
63+-- Create a dashed line style with a given color. Dashing equals `[8,4]`.
52dashed : Color -> LineStyle
64dashed : Color -> LineStyle
53dashed clr = { defaultLine | color <- clr, dashing <- [8,4] }
65dashed clr = { defaultLine | color <- clr, dashing <- [8,4] }
67+-- Create a dotted line style with a given color. Dashing equals `[3,3]`.
54dotted : Color -> LineStyle
68dotted : Color -> LineStyle
55dotted clr = { defaultLine | color <- clr, dashing <- [3,3] }
69dotted clr = { defaultLine | color <- clr, dashing <- [3,3] }
@@ -65,72 +79,106 @@ form f = { theta = 0, scale = 1, x = 0, y = 0, form = f }
66fill style shape = form (FShape (Right style) shape)
80fill style shape = form (FShape (Right style) shape)
82+-- Create a filled in shape.
68filled : Color -> Shape -> Form
83filled : Color -> Shape -> Form
69filled color shape = fill (Solid color) shape
84filled color shape = fill (Solid color) shape
86+-- Create a textured shape. The texture is described by some url and is
87+-- tiled to fill the entire shape.
71textured : String -> Shape -> Form
88textured : String -> Shape -> Form
72textured src shape = fill (Texture src) shape
89textured src shape = fill (Texture src) shape
91+-- Fill a shape with a [gradient](/docs/Color.elm#linear).
74gradient : Gradient -> Shape -> Form
92gradient : Gradient -> Shape -> Form
75gradient grad shape = fill (Gradient grad) shape
93gradient grad shape = fill (Gradient grad) shape
95+-- Outline a shape with a given line style.
77outlined : LineStyle -> Shape -> Form
96outlined : LineStyle -> Shape -> Form
78outlined style shape = form (FShape (Left style) shape)
97outlined style shape = form (FShape (Left style) shape)
99+-- Trace a path with a given line style.
80traced : LineStyle -> Path -> Form
100traced : LineStyle -> Path -> Form
81traced style path = form (FPath style path)
101traced style path = form (FPath style path)
83−-- Draw a sprite
103+-- Create a sprite from a sprite sheet. It cuts out a rectangle
84−-- w width
104+-- at a given position.
86−-- pos (px,py) coordinates into the sprite map
87−-- src The location of the image
88sprite : Int -> Int -> (Int,Int) -> String -> Form
105sprite : Int -> Int -> (Int,Int) -> String -> Form
89sprite w h pos src = form (FImage w h pos src)
106sprite w h pos src = form (FImage w h pos src)
108+-- Turn any `Element` into a `Form`. This lets you use text, gifs, and video
109+-- in your collage. This means you can move, rotate, and scale
110+-- an `Element` however you want.
91toForm : Element -> Form
111toForm : Element -> Form
92toForm e = form (FElement e)
112toForm e = form (FElement e)
114+-- Flatten many forms into a single `Form`. This lets you move and rotate them
115+-- as a single unit, making it possible to build small, modular components.
94group : [Form] -> Form
116group : [Form] -> Form
95group fs = form (FGroup Matrix.identity fs)
117group fs = form (FGroup Matrix.identity fs)
119+-- Flatten many forms into a single `Form` and then apply a matrix
97−groupTransform : Matrix -> [Form] -> Form
121+groupTransform : Matrix2D -> [Form] -> Form
98groupTransform matrix fs = form (FGroup matrix fs)
122groupTransform matrix fs = form (FGroup matrix fs)
124+-- Rotate a form by a given angle. Rotate takes standard Elm angles (radians)
125+-- and turns things counterclockwise. So to turn `form` 30° to the left
126+-- you would say, `(rotate (degrees 30) form)`.
100rotate : Float -> Form -> Form
127rotate : Float -> Form -> Form
101rotate t f = { f | theta <- f.theta + t }
128rotate t f = { f | theta <- f.theta + t }
130+-- Scale a form by a given factor. Scaling by 2 doubles the size.
103scale : Float -> Form -> Form
131scale : Float -> Form -> Form
104scale s f = { f | scale <- f.scale * s }
132scale s f = { f | scale <- f.scale * s }
134+-- Move a form by the given amount. This is a relative translation so
135+-- `(move (10,10) form)` would move `form` ten pixels up and ten pixels to the
106move : (Float,Float) -> Form -> Form
137move : (Float,Float) -> Form -> Form
107move (x,y) f = { f | x <- f.x + x, y <- f.y + y }
138move (x,y) f = { f | x <- f.x + x, y <- f.y + y }
140+-- Move a shape in the x direction. This is relative so `(moveX 10 form)` moves
141+-- `form` 10 pixels to the right.
109moveX : Float -> Form -> Form
142moveX : Float -> Form -> Form
110moveX x f = { f | x <- f.x + x }
143moveX x f = { f | x <- f.x + x }
145+-- Move a shape in the y direction. This is relative so `(moveY 10 form)` moves
146+-- `form` upwards by 10 pixels.
112moveY : Float -> Form -> Form
147moveY : Float -> Form -> Form
113moveY y f = { f | y <- f.y + y }
148moveY y f = { f | y <- f.y + y }
150+-- A collage is a collection of 2D forms. There are no strict positioning
151+-- relationships between forms, so you are free to do all kinds of 2D graphics.
115collage : Int -> Int -> [Form] -> Element
152collage : Int -> Int -> [Form] -> Element
118type Path = [(Float,Float)]
155type Path = [(Float,Float)]
157+-- Create a path that follows a sequence of points.
120path : [(Number a,Number a)] -> Path
158path : [(Number a,Number a)] -> Path
121path ps = ps
159path ps = ps
161+-- Create a path along a given line segment.
123segment : (Number a,Number a) -> (Number a,Number a) -> Path
162segment : (Number a,Number a) -> (Number a,Number a) -> Path
124segment p1 p2 = [p1,p2]
163segment p1 p2 = [p1,p2]
126type Shape = [(Float,Float)]
165type Shape = [(Float,Float)]
167+-- Create an arbitrary polygon by specifying its corners in order.
168+-- `polygon` will automatically close all shapes, so the given list
169+-- of points does not need to start and end with the same position.
128polygon : [(Number a,Number a)] -> Shape
170polygon : [(Number a,Number a)] -> Shape
129polygon points = points
171polygon points = points
173+-- A rectangle with a given width and height.
131rect : Number a -> Number a -> Shape
174rect : Number a -> Number a -> Shape
132rect w h = [ (0-w/2,0-h/2), (0-w/2,h/2), (w/2,h/2), (w/2,0-h/2) ]
175rect w h = [ (0-w/2,0-h/2), (0-w/2,h/2), (w/2,h/2), (w/2,0-h/2) ]
177+-- A square with a given edge length.
178+square : Number a -> Shape
181+-- An oval with a given width and height.
134oval : Number a -> Number a -> Shape
182oval : Number a -> Number a -> Shape
135oval w h =
183oval w h =
136 let n = 50
184 let n = 50
@@ -140,9 +188,15 @@ oval w h =
140 f i = (hw * Math.cos (t*i), hh * Math.sin (t*i))
188 f i = (hw * Math.cos (t*i), hh * Math.sin (t*i))
141 in map f [0..n-1]
189 in map f [0..n-1]
191+-- A circle with a given radius.
143circle : Number a -> Shape
192circle : Number a -> Shape
144circle r = oval (2*r) (2*r)
193circle r = oval (2*r) (2*r)
195+-- A regular polygon with N sides. The first argument specifies the number
196+-- of sides and the second is the radius. So to create a pentagon with radius
146ngon : Int -> Number a -> Shape
200ngon : Int -> Number a -> Shape
147ngon n r =
201ngon n r =
148 let m = toFloat n
202 let m = toFloat n