on master help sign in
Add lots of documentation and do some minor API clean up.
c92dd2fevancz
libraries/Automaton.elm+1
@@ -43,6 +43,7 @@ pure f = Step (\x -> (pure f, f x))
43-- function to step the state forward. For example, an automaton that counted
43-- function to step the state forward. For example, an automaton that counted
44-- how many steps it has taken would look like this:
44-- how many steps it has taken would look like this:
45--
45--
46+-- count = Automaton a Int
46-- count = state 0 (\\_ c -> c+1)
47-- count = state 0 (\\_ c -> c+1)
47--
48--
48-- It is a stateful automaton. The initial state is zero, and the step function
49-- It is a stateful automaton. The initial state is zero, and the step function
libraries/Color.elm+7−17
@@ -57,25 +57,15 @@ forestGreen = Color 34 139 34 1
57-- The two colors will accent each other.
57-- The two colors will accent each other.
58complement : Color -> Color
58complement : Color -> Color
59
59
60+-- Create [HSV colors](http://en.wikipedia.org/wiki/HSL_and_HSV)
60−-- Create HSV colors with an alpha component for transparency.
61+-- with an alpha component for transparency.
61−-- The alpha component is specified with numbers between 0 and 1.
62−hsva : Int -> Float -> Float -> Float -> Color
62+hsva : Float -> Float -> Float -> Float -> Color
63
63
64−-- Create HSV colors. HSV stands for hue-saturation-value.
64+-- Create [HSV colors](http://en.wikipedia.org/wiki/HSL_and_HSV).
65−--
65+-- This is very convenient for creating colors that cycle and shift.
66−-- Hue is a degree from 0 to 360 representing a color wheel: red at 0°,
67−-- green at 120°, blue at 240°, and red again at 360°.
68−-- This makes it easy to cycle through colors and compute color complements,
69−-- triads, tetrads, etc.
70−--
71−-- Saturation is a number between 1 and 0 where lowering this number makes
72−-- your color more grey. This can help you tone a color down.
73−--
74−-- Value is also a number between 1 and 0. Lowering this number makes your
75−-- color more black.
76--
66--
77−-- Look up the “HSV cylinder” for more information.
67+-- hsv (degrees 240) 1 1 == blue
78−hsv : Int -> Float -> Float -> Color
68+hsv : Float -> Float -> Float -> Color
79
69
80data Gradient
70data Gradient
81 = Linear (Float,Float) (Float,Float) [(Float,Color)]
71 = Linear (Float,Float) (Float,Float) [(Float,Color)]
libraries/Graphics/Collage.elm+67−13
@@ -22,35 +22,49 @@ data FillStyle
22 | Texture String
22 | Texture String
23 | Gradient Gradient
23 | Gradient Gradient
24
24
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
27
27
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
30+-- defaults to 10.
31+data LineJoin = Smooth | Sharp Float | Clipped
32+
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,
33− miterLimit : Float,
34 dashing : [Int],
40 dashing : [Int],
35 dashOffset : Int
41 dashOffset : Int
36 }
42 }
37
43
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:
47+--
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,
46− miterLimit = 10
47 }
57 }
48
58
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 }
62+
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] }
66+
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] }
56
70
@@ -65,72 +79,106 @@ form f = { theta = 0, scale = 1, x = 0, y = 0, form = f }
65
79
66fill style shape = form (FShape (Right style) shape)
80fill style shape = form (FShape (Right style) shape)
67
81
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
70
85
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
73
90
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
76
94
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)
79
98
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)
82
102
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.
85−-- h height
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)
90
107
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)
93
113
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)
96
118
119+-- Flatten many forms into a single `Form` and then apply a matrix
120+-- transformation.
97−groupTransform : Matrix -> [Form] -> Form
121+groupTransform : Matrix2D -> [Form] -> Form
98groupTransform matrix fs = form (FGroup matrix fs)
122groupTransform matrix fs = form (FGroup matrix fs)
99
123
124+-- Rotate a form by a given angle. Rotate takes standard Elm angles (radians)
125+-- and turns things counterclockwise. So to turn `form` 30&deg; 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 }
102
129
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 }
105
133
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
136+-- right.
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 }
108
139
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 }
111
144
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 }
114
149
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
116
153
117
154
118type Path = [(Float,Float)]
155type Path = [(Float,Float)]
119
156
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
122
160
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]
125
164
126type Shape = [(Float,Float)]
165type Shape = [(Float,Float)]
127
166
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
130
172
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) ]
133
176
177+-- A square with a given edge length.
178+square : Number a -> Shape
179+square n = rect w h
180+
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]
142
190
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)
145
194
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
197+-- 30 you would say:
198+--
199+-- ngon 5 30
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
libraries/Graphics/Element.elm+49−3
@@ -30,15 +30,19 @@ type Properties = {
30
30
31type Element = { props : Properties, element : ElementPrim }
31type Element = { props : Properties, element : ElementPrim }
32
32
33+-- Get the width of an Element
33widthOf : Element -> Int
34widthOf : Element -> Int
34−widthOf e = e.props.width
35+widthOf e = e.props.width
35
36
37+-- Get the height of an Element
36heightOf : Element -> Int
38heightOf : Element -> Int
37heightOf e = e.props.height
39heightOf e = e.props.height
38
40
41+-- Get the width and height of an Element
39−sizeOf : Element -> Int
42+sizeOf : Element -> (Int,Int)
40−sizeOf e = (e.props.width, e.props.height)
43+sizeOf e = (e.props.width, e.props.height)
41
44
45+-- Create an `Element` with a given width.
42width : Int -> Element -> Element
46width : Int -> Element -> Element
43width nw e = let p = e.props
47width nw e = let p = e.props
44 props = case e.element of
48 props = case e.element of
@@ -47,6 +51,7 @@ width nw e = let p = e.props
47 _ -> p
51 _ -> p
48 in { element=e.element, props={props| width <- nw} }
52 in { element=e.element, props={props| width <- nw} }
49
53
54+-- Create an `Element` with a given height.
50height : Int -> Element -> Element
55height : Int -> Element -> Element
51height nh e = let p = e.props
56height nh e = let p = e.props
52 props = case e.element of
57 props = case e.element of
@@ -54,17 +59,24 @@ height nh e = let p = e.props
54 _ -> p
59 _ -> p
55 in { element=e.element, props={p| height <- nh} }
60 in { element=e.element, props={p| height <- nh} }
56
61
62+-- Create an `Element` with a given opacity. Opacity is a number between 0 and 1
63+-- where 0 means totally clear.
57opacity : Float -> Element -> Element
64opacity : Float -> Element -> Element
58opacity o e = let p = e.props in { element=e.element, props={p| opacity <- o} }
65opacity o e = let p = e.props in { element=e.element, props={p| opacity <- o} }
59
66
67+-- Create an `Element` with a given background color.
60color : Color -> Element -> Element
68color : Color -> Element -> Element
61color c e = let p = e.props in
69color c e = let p = e.props in
62 { element=e.element, props={p| color <- Just c} }
70 { element=e.element, props={p| color <- Just c} }
63
71
72+-- Create an `Element` with a tag. This lets you link directly to it.
73+-- The element `(tag "all-about-badgers" thirdParagraph)` can be reached
74+-- with a link lik this: `/facts-about-animals.elm#all-about-badgers`
64tag : String -> Element -> Element
75tag : String -> Element -> Element
65tag name e = let p = e.props in
76tag name e = let p = e.props in
66 { element=e.element, props={p| tag <- JS.fromString name} }
77 { element=e.element, props={p| tag <- JS.fromString name} }
67
78
79+-- Create an `Element` that is a hyper-link.
68link : String -> Element -> Element
80link : String -> Element -> Element
69link href e = let p = e.props in
81link href e = let p = e.props in
70 { element=e.element, props={p| href <- JS.fromString href} }
82 { element=e.element, props={p| href <- JS.fromString href} }
@@ -83,12 +95,20 @@ data ElementPrim
83
95
84data ImageStyle = Plain | Fitted | Cropped (Int,Int)
96data ImageStyle = Plain | Fitted | Cropped (Int,Int)
85
97
98+-- Create an image given a width, height, and image source.
86image : Int -> Int -> String -> Element
99image : Int -> Int -> String -> Element
87image w h src = newElement w h (Image Plain w h (JS.fromString src))
100image w h src = newElement w h (Image Plain w h (JS.fromString src))
88
101
102+-- Create a fitted image given a width, height, and image source.
103+-- This will crop the picture to best fill the given dimensions.
89fittedImage : Int -> Int -> String -> Element
104fittedImage : Int -> Int -> String -> Element
90fittedImage w h src = newElement w h (Image Fitted w h (JS.fromString src))
105fittedImage w h src = newElement w h (Image Fitted w h (JS.fromString src))
91
106
107+-- Create a cropped image. Take a rectangle out of the picture starting
108+-- at the given top left coordinate. If you have a 140-by-140 image,
109+-- the following will cut a 100-by-100 square out of the middle of it.
110+--
111+-- croppedImage 100 100 (20,20) "yogi.jpg"
92croppedImage : Int -> Int -> (Int,Int) -> String -> Element
112croppedImage : Int -> Int -> (Int,Int) -> String -> Element
93croppedImage w h pos src =
113croppedImage w h pos src =
94 newElement w h (Image (Cropped pos) w h (JS.fromString src))
114 newElement w h (Image (Cropped pos) w h (JS.fromString src))
@@ -97,14 +117,31 @@ data Three = P | Z | N
97data Pos = Absolute Int | Relative Float
117data Pos = Absolute Int | Relative Float
98type Position = { horizontal : Three, vertical : Three, x : Pos, y : Pos }
118type Position = { horizontal : Three, vertical : Three, x : Pos, y : Pos }
99
119
120+-- Put an element in a container. This lets you position the element really
121+-- easily, and there are tons of ways to set the `Position`.
122+-- To center `element` exactly in a 300-by-300 square you would say:
123+--
124+-- container 300 300 middle element
125+--
126+-- By setting the color of the container, you can create borders.
100container : Int -> Int -> Position -> Element -> Element
127container : Int -> Int -> Position -> Element -> Element
101container w h pos e = newElement w h (Container pos e)
128container w h pos e = newElement w h (Container pos e)
102
129
130+-- Create an empty box. This is useful for getting your spacing right and
131+-- for making borders.
103spacer : Int -> Int -> Element
132spacer : Int -> Int -> Element
104spacer w h = newElement w h Spacer
133spacer w h = newElement w h Spacer
105
134
106data Direction = DUp | DDown | DLeft | DRight | DIn | DOut
135data Direction = DUp | DDown | DLeft | DRight | DIn | DOut
107
136
137+-- Have a list of elements flow in a particular direction.
138+-- The `Direction` starts from the first element in the list.
139+--
140+-- flow right [a,b,c]
141+--
142+-- +---+---+---+
143+-- | a | b | c |
144+-- +---+---+---+
108flow : Direction -> [Element] -> Element
145flow : Direction -> [Element] -> Element
109flow dir es =
146flow dir es =
110 let ws = List.map widthOf es
147 let ws = List.map widthOf es
@@ -120,24 +157,33 @@ flow dir es =
120 DIn -> newFlow (List.maximum ws) (List.maximum hs)
157 DIn -> newFlow (List.maximum ws) (List.maximum hs)
121 DOut -> newFlow (List.maximum ws) (List.maximum hs)
158 DOut -> newFlow (List.maximum ws) (List.maximum hs)
122
159
160+-- Stack elements vertically. To put `a` above `b` you would say:
161+--
162+-- a `above` b
123above : Element -> Element -> Element
163above : Element -> Element -> Element
124above hi lo =
164above hi lo =
125 newElement (max (widthOf hi) (widthOf lo))
165 newElement (max (widthOf hi) (widthOf lo))
126 (heightOf hi + heightOf lo)
166 (heightOf hi + heightOf lo)
127 (Flow DDown [hi,lo])
167 (Flow DDown [hi,lo])
128
168
169+-- Stack elements vertically. To put `a` below `b` you would say:
170+--
171+-- a `below` b
129below : Element -> Element -> Element
172below : Element -> Element -> Element
130below lo hi =
173below lo hi =
131 newElement (max (widthOf hi) (widthOf lo))
174 newElement (max (widthOf hi) (widthOf lo))
132 (heightOf hi + heightOf lo)
175 (heightOf hi + heightOf lo)
133 (Flow DDown [hi,lo])
176 (Flow DDown [hi,lo])
134
177
178+-- Put elements beside each other horizontally.
135beside : Element -> Element -> Element
179beside : Element -> Element -> Element
136beside lft rht =
180beside lft rht =
137 newElement (widthOf lft + widthOf rht)
181 newElement (widthOf lft + widthOf rht)
138 (max (heightOf lft) (heightOf rht))
182 (max (heightOf lft) (heightOf rht))
139 (Flow right [lft,rht])
183 (Flow right [lft,rht])
140
184
185+-- Layer elements on top of each other, starting from the bottom.
186+-- `(layers == flow outward)`
141layers : [Element] -> Element
187layers : [Element] -> Element
142layers es =
188layers es =
143 let ws = List.map widthOf es
189 let ws = List.map widthOf es
libraries/JavaScript.elm+7−20
@@ -2,38 +2,25 @@
2module JavaScript where
2module JavaScript where
3
3
4
4
5−-- To Elm
6−
7−toString : JSString -> String
8−
9-- Requires that the input array be uniform (all members have the same type)
5-- Requires that the input array be uniform (all members have the same type)
10toList : JSArray a -> [a]
6toList : JSArray a -> [a]
11−
12toInt : JSNumber -> Int
7toInt : JSNumber -> Int
13toFloat : JSNumber -> Float
8toFloat : JSNumber -> Float
14toBool : JSBool -> Bool
9toBool : JSBool -> Bool
10+toString : JSString -> String
15
11
16
12
17−-- From Elm
18−
19−fromString : String -> JSString
20−
21-- Produces a uniform JavaScript array with all members of the same type.
13-- Produces a uniform JavaScript array with all members of the same type.
22fromList : [a] -> JSArray a
14fromList : [a] -> JSArray a
23−
24fromInt : Int -> JSNumber
15fromInt : Int -> JSNumber
25fromFloat : Float -> JSNumber
16fromFloat : Float -> JSNumber
26fromBool : Bool -> JSBool
17fromBool : Bool -> JSBool
18+fromString : String -> JSString
27
19
28−{-- TODO: only found in docs
29
20
30− , ("castTupleToJSTuple2" , "(a,b) -> JSTuple2 a b", "A JSTupleN is an array of size N with nonuniform types. Each member can have a different type.")
21+-- Turn an `Element` into a plain old DOM node.
31− , ("castJSTupleToTuple2" , "JSTuple2 a b -> (a,b)", "")
22+fromElement : Element -> JSDomNode
32− , ("castTupleToJSTuple3" , "(a,b,c) -> JSTuple3 a b c", "")
33− , ("castJSTupleToTuple3" , "JSTuple3 a b c > (a,b,c)", "")
34− , ("castTupleToJSTuple4" , "(a,b,c,d) -> JSTuple4 a b c d", "")
35− , ("castJSTupleToTuple4" , "JSTuple4 a b c d -> (a,b,c,d)", "")
36− , ("castTupleToJSTuple5" , "(a,b,c,d,e) -> JSTuple5 a b c d e", "")
37− , ("castJSTupleToTuple5" , "JSTuple5 a b c d e -> (a,b,c,d,e)", "")
38
23
39−--}
24+-- Turn a DOM node into an `Element`. You can resize the node
25+-- using the normal `width` and `height` functions.
26+toElement : Int -> Int -> JSDomNode -> Element
libraries/JavaScript/Experimental.elm+21
@@ -3,8 +3,29 @@ module JavaScript.Experimental where
3
3
4import JavaScript as JS
4import JavaScript as JS
5
5
6+-- Turn arbitrary JavaScript objects into Elm records.
7+-- Arrays are converted into lists, nested objects are allowed.
8+-- No `null` values or non-homogeneous arrays.
9+--
10+-- -- OK objects
11+-- { student:"Steve", scores:[83,94,99,72] }
12+-- { errorLevel:10, critical:true }
13+--
14+-- -- BAD objects
15+-- { answer = null }
16+-- { info = [true,42,'what'] }
6toRecord : JSObject -> a
17toRecord : JSObject -> a
7toRecord = JS.toRecord
18toRecord = JS.toRecord
8
19
20+-- Turn arbitrary Elm records into JavaScript objects.
21+-- Lists become arrays, nested records are allowed. No ADTs.
22+--
23+-- -- OK records
24+-- { student="Steve", scores=[83,94,99,72] }
25+-- { errorLevel=10, critical=True }
26+--
27+-- -- BAD records
28+-- { answer = Nothing }
29+-- { result = Left "An error occurred" }
9fromRecord : a -> JSObject
30fromRecord : a -> JSObject
10fromRecord = JS.fromRecord
31fromRecord = JS.fromRecord
libraries/Keyboard.elm+6−6
@@ -1,17 +1,17 @@
1−-- These are nicely curated inputs from the keyboard. See the
2−-- [Keyboard.Raw library](/docs/Signal/KeyboardRaw.elm) for a
3−-- lower-level interface that will let you define more complicated behavior.
4module Keyboard where
1module Keyboard where
5
2
6import Native.Keyboard as N
3import Native.Keyboard as N
7
4
5+-- Type alias to make it clearer what integers are supposed to represent
6+-- in this library. Use [`Char.toCode`](docs/Char.elm#toCode) and
7+-- [`Char.fromCode`](/docs/Char.elm#fromCode) to convert key codes to characters.
8type KeyCode = Int
8type KeyCode = Int
9
9
10-- A signal of records indicating which arrow keys are pressed.
10-- A signal of records indicating which arrow keys are pressed.
11--
11--
12−-- `{ x = 0, y = 0 }` when pressing no arrows.
12+-- `{ x = 0, y = 0 }` when pressing no arrows.<br>
13−-- `{ x =-1, y = 0 }` when pressing the left arrow.
13+-- `{ x =-1, y = 0 }` when pressing the left arrow.<br>
14−-- `{ x = 1, y = 1 }` when pressing the up and right arrows.
14+-- `{ x = 1, y = 1 }` when pressing the up and right arrows.<br>
15-- `{ x = 0, y =-1 }` when pressing the down, left, and right arrows.
15-- `{ x = 0, y =-1 }` when pressing the down, left, and right arrows.
16arrows : Signal { x:Int, y:Int }
16arrows : Signal { x:Int, y:Int }
17arrows = N.directions 38 40 37 39
17arrows = N.directions 38 40 37 39
libraries/List.elm+40−22
@@ -4,29 +4,34 @@ module List where
4import Native.Utils (min, max)
4import Native.Utils (min, max)
5import Native.List as L
5import Native.List as L
6
6
7−-- Add an element to the front of a list
7+-- Add an element to the front of a list `(1 :: [2,3] == [1,2,3])`
8−-- a :: [b,c] = [a,b,c]
9(::) : a -> [a] -> [a]
8(::) : a -> [a] -> [a]
10
9
11−-- Appends two lists.
10+-- Puts two appendable things together:
11+--
12+-- [1,1] ++ [2,3] == [1,1,2,3]
13+-- "abc" ++ "123" == "abc123"
12(++) : Appendable a -> Appendable a -> Appendable a
14(++) : Appendable a -> Appendable a -> Appendable a
13
15
14-- Extract the first element of a list. List must be non-empty.
16-- Extract the first element of a list. List must be non-empty.
17+-- `(head [1,2,3] == 1)`
15head : [a] -> a
18head : [a] -> a
16
19
17-- Extract the elements after the head of the list. List must be non-empty.
20-- Extract the elements after the head of the list. List must be non-empty.
21+-- `(tail [1,2,3] == [2,3])`
18tail : [a] -> [a]
22tail : [a] -> [a]
19
23
20-- Extract the last element of a list. List must be non-empty.
24-- Extract the last element of a list. List must be non-empty.
25+-- `(last [1,2,3] == 3)`
21last : [a] -> a
26last : [a] -> a
22
27
23−-- Apply a function to every element of a list.
28+-- Apply a function to every element of a list: `(map sqrt [1,4,9] == [1,2,3])`
24map : (a -> b) -> [a] -> [b]
29map : (a -> b) -> [a] -> [b]
25
30
26−-- Reduce a list from the left.
31+-- Reduce a list from the left: `(foldl (::) [] "gateman" == "nametag")`
27foldl : (a -> b -> b) -> b -> [a] -> b
32foldl : (a -> b -> b) -> b -> [a] -> b
28
33
29−-- Reduce a list from the right.
34+-- Reduce a list from the right: `(foldr (+) 0 [1,2,3] == 6)`
30foldr : (a -> b -> b) -> b -> [a] -> b
35foldr : (a -> b -> b) -> b -> [a] -> b
31
36
32-- Reduce a list from the left without a base case. List must be non-empty.
37-- Reduce a list from the left without a base case. List must be non-empty.
@@ -36,18 +41,22 @@ foldl1 : (a -> a -> a) -> [a] -> a
36foldr1 : (a -> a -> a) -> [a] -> a
41foldr1 : (a -> a -> a) -> [a] -> a
37
42
38-- Reduce a list from the left, building up all of the intermediate results into a list.
43-- Reduce a list from the left, building up all of the intermediate results into a list.
44+--
45+-- scanl (+) 0 [1,2,3,4] == [0,1,3,6,10]
39scanl : (a -> b -> b) -> b -> [a] -> [b]
46scanl : (a -> b -> b) -> b -> [a] -> [b]
40
47
41-- Same as scanl but it doesn't require a base case. List must be non-empty.
48-- Same as scanl but it doesn't require a base case. List must be non-empty.
49+--
50+-- scanl1 (+) [1,2,3,4] == [1,3,6,10]
42scanl1 : (a -> a -> a) -> [a] -> [a]
51scanl1 : (a -> a -> a) -> [a] -> [a]
43
52
44−-- Filter out elements which do not satisfy the predicate.
53+-- Filter out elements which do not satisfy the predicate: `(filter isLower "AaBbCc" == "abc")`
45filter : (a -> Bool) -> [a] -> [a]
54filter : (a -> Bool) -> [a] -> [a]
46
55
47−-- Determine the length of a list.
56+-- Determine the length of a list: `(length "innumerable" == 11)`
48length : [a] -> Int
57length : [a] -> Int
49
58
50−-- Reverse a list.
59+-- Reverse a list. `(reverse [1..4] == [4,3,2,1])`
51reverse : [a] -> [a]
60reverse : [a] -> [a]
52
61
53-- Check to see if all elements satisfy the predicate.
62-- Check to see if all elements satisfy the predicate.
@@ -62,29 +71,31 @@ and : [Bool] -> Bool
62-- Check to see if any elements are True.
71-- Check to see if any elements are True.
63or : [Bool] -> Bool
72or : [Bool] -> Bool
64
73
65−-- Flatten a list of lists.
74+-- Concatenate a list of appendable things:
75+--
76+-- concat ["tree","house"] == "treehouse"
66concat : [Appendable a] -> Appendable a
77concat : [Appendable a] -> Appendable a
67
78
68-- Map a given function onto a list and flatten the resulting lists.
79-- Map a given function onto a list and flatten the resulting lists.
69--
80--
70−-- concatMap f xs == concat (map f xs)
81+-- concatMap f xs == concat (map f xs)
71concatMap : (a -> Appendable b) -> [a] -> Appendable b
82concatMap : (a -> Appendable b) -> [a] -> Appendable b
72concatMap f = L.concat . L.map f
83concatMap f = L.concat . L.map f
73
84
74−-- Get the sum of the list elements.
85+-- Get the sum of the list elements. `(sum [1..4] == 10)`
75sum : [Number a] -> Number a
86sum : [Number a] -> Number a
76sum = L.foldl (+) 0
87sum = L.foldl (+) 0
77
88
78−-- Get the product of the list elements.
89+-- Get the product of the list elements. `(product [1..4] == 24)`
79product : [Number a] -> Number a
90product : [Number a] -> Number a
80product = L.foldl (*) 1
91product = L.foldl (*) 1
81
92
82-- Find the highest number in a non-empty list.
93-- Find the highest number in a non-empty list.
83−maximum : [Comparable a] -> Comparable a
94+maximum : [Number a] -> Number a
84maximum = L.foldl1 max
95maximum = L.foldl1 max
85
96
86-- Find the lowest number in a non-empty list.
97-- Find the lowest number in a non-empty list.
87−minimum : [Comparable a] -> Comparable a
98+minimum : [Number a] -> Number a
88minimum = L.foldl1 min
99minimum = L.foldl1 min
89
100
90-- Split a list based on the predicate.
101-- Split a list based on the predicate.
@@ -95,13 +106,20 @@ partition pred lst =
95 x::xs -> let (bs,cs) = partition pred xs in
106 x::xs -> let (bs,cs) = partition pred xs in
96 if pred x then (x::bs,cs) else (bs,x::cs)
107 if pred x then (x::bs,cs) else (bs,x::cs)
97
108
98−-- Combine two lists, combining them into tuples pairwise. If one input list has extra elements (it is longer), those elements are dropped.
109+-- Combine two lists, combining them into tuples pairwise.
110+-- If one list is longer, the extra elements are dropped.
111+--
112+-- zip [1,2,3] [6,7] == [(1,6),(2,7)]
113+-- zip == zipWith (,)
99zip : [a] -> [b] -> [(a,b)]
114zip : [a] -> [b] -> [(a,b)]
100
115
101−-- Combine two lists, combining them with the given function. If one input list has extra elements (it is longer), those elements are dropped.
116+-- Combine two lists, combining them with the given function.
117+-- If one list is longer, the extra elements are dropped.
118+--
119+-- zipWith (+) [1,2,3] [1,2,3,4] == [2,4,6]
102zipWith : (a -> b -> c) -> [a] -> [b] -> [c]
120zipWith : (a -> b -> c) -> [a] -> [b] -> [c]
103
121
104−-- Decompose a list of tuples
122+-- Decompose a list of tuples.
105unzip : [(a,b)] -> ([a],[b])
123unzip : [(a,b)] -> ([a],[b])
106unzip pairs =
124unzip pairs =
107 case pairs of
125 case pairs of
@@ -120,6 +138,8 @@ split : [a] -> [a] -> [[a]]
120join : Appendable a -> [Appendable a] -> Appendable a
138join : Appendable a -> [Appendable a] -> Appendable a
121
139
122-- Places the given value between all members of the given list.
140-- Places the given value between all members of the given list.
141+--
142+-- intersperse ' ' "INCEPTION" == "I N C E P T I O N"
123intersperse : a -> [a] -> [a]
143intersperse : a -> [a] -> [a]
124intersperse sep xs =
144intersperse sep xs =
125 case xs of
145 case xs of
@@ -127,11 +147,9 @@ intersperse sep xs =
127 [a] -> [a]
147 [a] -> [a]
128 [] -> []
148 [] -> []
129
149
130−-- Take the first n members of a list.
150+-- Take the first n members of a list: `(take 2 [1,2,3,4] == [1,2])`
131−-- take 2 [1,2,3,4]) ==> [1,2]
132take : Int -> [a] -> [a]
151take : Int -> [a] -> [a]
133
152
134−-- Drop the first n members of a list.
153+-- Drop the first n members of a list: `(drop 2 [1,2,3,4] == [3,4])`
135−-- drop 2 [1,2,3,4]) ==> [3,4]
136drop : Int -> [a] -> [a]
154drop : Int -> [a] -> [a]
137
155
libraries/Matrix2D.elm+29−11
@@ -3,16 +3,34 @@ module Matrix2D where
3
3
4import Native.Matrix2D as M
4import Native.Matrix2D as M
5
5
6+-- Create an identity matrix.
7+--
8+-- / 1 0 \\
9+-- \\ 0 1 /
6−identity : Matrix
10+identity : Matrix2D
7
11
8−transform : Float -> Float -> Float -> Float -> Float -> Float -> Matrix -> Matrix
12+-- Creates an arbitrary matrix. This lets you create scales, shears, reflections,
9−rotate : Float -> Matrix -> Matrix
13+-- translations, or any other 2D transform.
10−move : (Float,Float) -> Matrix -> Matrix
14+--
11−scale : Float -> Matrix -> Matrix
15+-- matrix a b c d dx dy
12−scaleX : Float -> Matrix -> Matrix
16+--
13−scaleY : Float -> Matrix -> Matrix
17+-- / a b \\
14−reflectX : Matrix -> Matrix
18+-- \\ c d /
15−reflectY : Matrix -> Matrix
19+--
20+-- And `dx` and `dy` are the translation values.
21+matrix : Float -> Float -> Float -> Float -> Float -> Float -> Matrix2D
16
22
17−multiply : Matrix -> Matrix -> Matrix
23+-- Creates a [rotation matrix](http://en.wikipedia.org/wiki/Rotation_matrix).
18−matrix : Float -> Float -> Float -> Float -> Float -> Float -> Matrix
24+-- Given an angle t, it creates a counterclockwise rotation matrix:
25+--
26+-- / cos t -sin t \\
27+-- \\ sin t cos t /
28+rotation : Float -> Matrix2D
29+
30+-- Multiplies two matrices together:
31+--
32+-- multiply a b
33+--
34+-- / a11 a12 \\ . / b11 b12 \\
35+-- \\ a21 a22 / \\ b21 b22 /
36+multiply : Matrix2D -> Matrix2D -> Matrix2D
libraries/Mouse.elm−2
@@ -12,7 +12,6 @@ x : Signal Int
12-- The current y-coordinate of the mouse.
12-- The current y-coordinate of the mouse.
13y : Signal Int
13y : Signal Int
14
14
15−
16-- The current state of the left mouse-button.
15-- The current state of the left mouse-button.
17-- True when the button is down, and false otherwise.
16-- True when the button is down, and false otherwise.
18isDown : Signal Bool
17isDown : Signal Bool
@@ -20,7 +19,6 @@ isDown : Signal Bool
20-- True immediately after the left mouse-button has been clicked,
19-- True immediately after the left mouse-button has been clicked,
21-- and false otherwise.
20-- and false otherwise.
22isClicked : Signal Bool
21isClicked : Signal Bool
23−
24
22
25-- Always equal to unit. Event triggers on every mouse click.
23-- Always equal to unit. Event triggers on every mouse click.
26clicks : Signal ()
24clicks : Signal ()
libraries/Native/Color.js+13−7
@@ -6,19 +6,25 @@ Elm.Native.Color = function(elm) {
6 elm.Native = elm.Native || {};
6 elm.Native = elm.Native || {};
7 if (elm.Native.Color) return elm.Native.Color;
7 if (elm.Native.Color) return elm.Native.Color;
8
8
9+ var Utils = Elm.Native.Utils(elm);
10+
9 function complement(rgb) {
11 function complement(rgb) {
10− var hsv = toHSV(rgb);
12+ var hsv = toHSV(rgb);
11− hsv.hue = (hsv.hue + 180) % 360;
13+ hsv.hue = (hsv.hue + 180) % 360;
12− return toRGB(hsv);
14+ return toRGB(hsv);
13 }
15 }
14
16
15 function hsva(h,s,v,a) {
17 function hsva(h,s,v,a) {
18+ var degree = A2(Utils.mod, h * 180 / Math.PI, 360);
16− var clr = toRGB({hue:h, saturation:s, value:v});
19+ var clr = toRGB({hue:degree, saturation:s, value:v});
17− clr._3 = a;
20+ clr._3 = a;
18− return clr;
21+ return clr;
19 }
22 }
20
23
24+ function hsv(h,s,v) {
25+ var degree = A2(Utils.mod, h * 180 / Math.PI, 360);
21− function hsv(h,s,v) { return toRGB({hue:h, saturation:s, value:v}); }
26+ return toRGB({hue:degree, saturation:s, value:v});
27+ }
22
28
23 function toHSV(rgb) {
29 function toHSV(rgb) {
24 var hsv = {};
30 var hsv = {};
libraries/Native/Graphics/Input.js−1
@@ -31,7 +31,6 @@ Elm.Native.Graphics.Input = function(elm) {
31 node.elmEvent = newModel.event;
31 node.elmEvent = newModel.event;
32 var txt = newModel.text;
32 var txt = newModel.text;
33 if (oldModel.text !== txt) node.innerHTML = txt;
33 if (oldModel.text !== txt) node.innerHTML = txt;
34− return true;
35 }
34 }
36
35
37 function button(evnt, txt) {
36 function button(evnt, txt) {
libraries/Native/JavaScript.js+24−3
@@ -6,6 +6,7 @@ Elm.Native.JavaScript = function(elm) {
6 if (elm.Native.JavaScript) return elm.Native.JavaScript;
6 if (elm.Native.JavaScript) return elm.Native.JavaScript;
7
7
8 var List = Elm.Native.List(elm);
8 var List = Elm.Native.List(elm);
9+ var Render = ElmRuntime.use(ElmRuntime.Render.Element);
9
10
10 function fromJS(v) {
11 function fromJS(v) {
11 var type = typeof v;
12 var type = typeof v;
@@ -61,7 +62,24 @@ Elm.Native.JavaScript = function(elm) {
61 throw new Error("'fromRecord' must be called on a record.");
62 throw new Error("'fromRecord' must be called on a record.");
62 }
63 }
63
64
64− function id(n) { return n }
65+ function id(n) { return n; }
66+
67+ function toElement(w,h,domNode) {
68+ return A3( newElement, w, h, {
69+ ctor: 'Custom',
70+ type: 'DomNode',
71+ render: function(node) { return node; },
72+ update: function(node,oldNode,newNode) {
73+ if (node === newNode) return;
74+ node.parentNode.replaceChild(newNode, node);
75+ },
76+ model: domNode
77+ });
78+ }
79+
80+ function fromElement(element) {
81+ return Render.render(element);
82+ }
65
83
66 return elm.Native.JavaScript = {
84 return elm.Native.JavaScript = {
67 toFloat : id,
85 toFloat : id,
@@ -74,8 +92,11 @@ Elm.Native.JavaScript = function(elm) {
74 fromInt : id,
92 fromInt : id,
75 fromFloat : id,
93 fromFloat : id,
76 fromBool : id,
94 fromBool : id,
95+
96+ toElement : toElement,
97+ fromElement : fromElement,
77− toRecord : fromJS,
98+ toRecord : fromJS,
78− fromRecord : fromRecord
99+ fromRecord : fromRecord
79 };
100 };
80
101
81};
102};
libraries/Native/Matrix2D.js+12−4
@@ -17,9 +17,14 @@ Elm.Native.Matrix2D = function(elm) {
17 // new A([ m11, m12, dx, m21, m22, dy ])
17 // new A([ m11, m12, dx, m21, m22, dy ])
18
18
19 var identity = new A([1,0,0,0,1,0]);
19 var identity = new A([1,0,0,0,1,0]);
20− function matrix(m11, m21, m12, m22, dx, dy) {
20+ function matrix(m11, m12, m21, m22, dx, dy) {
21 return new A([m11, m12, dx, m21, m22, dy]);
21 return new A([m11, m12, dx, m21, m22, dy]);
22 }
22 }
23+ function rotation(t) {
24+ var c = Math.cos(t);
25+ var s = Math.sin(t);
26+ return new A([c, -s, 0, s, c, 0]);
27+ }
23
28
24 function rotate(t,m) {
29 function rotate(t,m) {
25 var c = Math.cos(t);
30 var c = Math.cos(t);
@@ -28,6 +33,7 @@ Elm.Native.Matrix2D = function(elm) {
28 return new A([m11*c + m12*s, -m11*s + m12*c, m[2],
33 return new A([m11*c + m12*s, -m11*s + m12*c, m[2],
29 m21*c + m22*s, -m21*s + m22*c, m[5]]);
34 m21*c + m22*s, -m21*s + m22*c, m[5]]);
30 }
35 }
36+ /*
31 function move(xy,m) {
37 function move(xy,m) {
32 var x = xy._0;
38 var x = xy._0;
33 var y = xy._1;
39 var y = xy._1;
@@ -50,7 +56,7 @@ Elm.Native.Matrix2D = function(elm) {
50 m21*n12 + m22*n22,
56 m21*n12 + m22*n22,
51 m21*ndx + m22*ndy + mdy]);
57 m21*ndx + m22*ndy + mdy]);
52 }
58 }
53−
59+ */
54 function multiply(m, n) {
60 function multiply(m, n) {
55 return transform(m[0], m[3], m[1], m[4], m[2], m[5], n);
61 return transform(m[0], m[3], m[1], m[4], m[2], m[5], n);
56 }
62 }
@@ -58,8 +64,9 @@ Elm.Native.Matrix2D = function(elm) {
58 return elm.Native.Matrix2D = {
64 return elm.Native.Matrix2D = {
59 identity:identity,
65 identity:identity,
60 matrix:F6(matrix),
66 matrix:F6(matrix),
67+ rotation:rotation,
61− multiply:F2(multiply),
68+ multiply:F2(multiply)
62−
69+ /*
63 transform:F7(transform),
70 transform:F7(transform),
64 rotate:F2(rotate),
71 rotate:F2(rotate),
65 move:F2(move),
72 move:F2(move),
@@ -68,6 +75,7 @@ Elm.Native.Matrix2D = function(elm) {
68 scaleY:F2(scaleY),
75 scaleY:F2(scaleY),
69 reflectX:reflectX,
76 reflectX:reflectX,
70 reflectY:reflectY
77 reflectY:reflectY
78+ */
71 };
79 };
72
80
73};
81};
libraries/Native/Prelude.js+1−6
@@ -10,12 +10,7 @@ Elm.Native.Prelude = function(elm) {
10
10
11 function div(a,b) { return (a/b)|0; }
11 function div(a,b) { return (a/b)|0; }
12 function rem(a,b) { return a % b; }
12 function rem(a,b) { return a % b; }
13− function mod(a,b) {
13+ var mod = Utils.mod;
14− var r = a % b;
15− var m = a === 0 ? 0 : (b > 0 ? (a >= 0 ? r : r+b) : -mod(-a,-b));
16−
17− return m === b ? 0 : m;
18− }
19 function abs(x) { return x < 0 ? -x : x; }
14 function abs(x) { return x < 0 ? -x : x; }
20 function logBase(base,n) { return Math.log(n) / Math.log(base); }
15 function logBase(base,n) { return Math.log(n) / Math.log(base); }
21 function min(a,b) { return a < b ? a : b; }
16 function min(a,b) { return a < b ? a : b; }
libraries/Native/Utils.js+8
@@ -98,6 +98,13 @@ Elm.Native.Utils = function(elm) {
98 function max(a,b) { return a > b ? a : b }
98 function max(a,b) { return a > b ? a : b }
99 function min(a,b) { return a < b ? a : b }
99 function min(a,b) { return a < b ? a : b }
100
100
101+ function mod(a,b) {
102+ var r = a % b;
103+ var m = a === 0 ? 0 : (b > 0 ? (a >= 0 ? r : r+b) : -mod(-a,-b));
104+
105+ return m === b ? 0 : m;
106+ }
107+
101 function htmlHeight(width, html) {
108 function htmlHeight(width, html) {
102 var t = document.createElement('div');
109 var t = document.createElement('div');
103 t.innerHTML = html;
110 t.innerHTML = html;
@@ -143,6 +150,7 @@ Elm.Native.Utils = function(elm) {
143 guid: guid,
150 guid: guid,
144 max : F2(max),
151 max : F2(max),
145 min : F2(min),
152 min : F2(min),
153+ mod : F2(mod),
146 htmlHeight: F2(htmlHeight),
154 htmlHeight: F2(htmlHeight),
147 toFloat: function(x){return x}
155 toFloat: function(x){return x}
148 };
156 };
libraries/Signal.elm+4−2
@@ -95,6 +95,8 @@ sampleOn : Signal a -> Signal b -> Signal b
95
95
96-- An alias for `lift`. A prettier way to apply a
96-- An alias for `lift`. A prettier way to apply a
97-- function to the current value of a signal.
97-- function to the current value of a signal.
98+--
99+-- lift f signal == f <~ signal
98(<~) : (a -> b) -> Signal a -> Signal b
100(<~) : (a -> b) -> Signal a -> Signal b
99
101
100-- Signal application. This takes two signals, holding a function and
102-- Signal application. This takes two signals, holding a function and
@@ -102,6 +104,6 @@ sampleOn : Signal a -> Signal b -> Signal b
102--
104--
103-- So the following expressions are equivalent:
105-- So the following expressions are equivalent:
104--
106--
105−-- scene <~ Mouse.x ~ Mouse.y
107+-- scene <~ Window.dimensions ~ Mouse.position
106−-- lift2 scene Mouse.x Mouse.y
108+-- lift2 scene Window.dimensions Mouse.position
107(~) : Signal (a -> b) -> Signal a -> Signal b
109(~) : Signal (a -> b) -> Signal a -> Signal b
libraries/Text.elm+5−3
@@ -56,8 +56,10 @@ text : Text -> Element
56
56
57-- Display a plain string.
57-- Display a plain string.
58plainText : String -> Element
58plainText : String -> Element
59−
59+
60-- Convert anything to it's textual representation and make it displayable in browser
60-- Convert anything to it's textual representation and make it displayable in browser
61+--
61−-- asText = text . monospace . show
62+-- asText == text . monospace . show
63+--
62−-- Excellent for debugging
64+-- Excellent for debugging.
63asText : a -> Element
65asText : a -> Element
libraries/Time.elm+8−6
@@ -3,13 +3,15 @@ module Time where
3
3
4import Native.Time as T
4import Native.Time as T
5
5
6+-- Type alias to make it clearer when you are working with time values.
7+-- Using the `Time` constants instead of raw numbers is very highly recommended.
6type Time = Float
8type Time = Float
7
9
8-- Units of time, making it easier to specify things like a
10-- Units of time, making it easier to specify things like a
9−-- half-second `(second / 2)`.
11+-- half-second `(500 * milliseconds)` without remembering Elm&rsquo;s
10−
12+-- underlying units of time.
11−ms : Time
13+millisecond : Time
12−ms = 1
14+millisecond = 1
13
15
14second : Time
16second : Time
15second = 1000 * ms
17second = 1000 * ms
@@ -20,8 +22,8 @@ minute = 60 * second
20hour : Time
22hour : Time
21hour = 60 * minute
23hour = 60 * minute
22
24
23−inMss : Time -> Float
25+inMilliseconds : Time -> Float
24−inMss t = t
26+inMilliseconds t = t
25
27
26inSeconds : Time -> Float
28inSeconds : Time -> Float
27inSeconds t = t / second
29inSeconds t = t / second
libraries/Touch.elm+8−6
@@ -4,13 +4,15 @@ module Touch where
4
4
5import Native.Touch as T
5import Native.Touch as T
6
6
7+-- Every `Touch` has `xy` coordinates. It also has an identifier `id` to
8+-- distinguish one touch from another.
9+--
10+-- A touch also keeps info about the intial point and time of contact:
11+-- `x0`, `y0`, and `t0`. This helps compute more complicated gestures
12+-- like taps, drags, and swipes which need to know about timing or direction.
7−-- type Touch = { x:Int, y:Int, id:Int, x0:Int, y0:Int, t0:Time }
13+type Touch = { x:Int, y:Int, id:Int, x0:Int, y0:Int, t0:Time }
8
14
9−-- A list of touches. Each ongoing touch is represented by a set of
15+-- A list of ongoing touches.
10−-- coordinates and an identifier id that allows you to distinguish
11−-- between different touches. Each touch also contains the coordinates and
12−-- time of the initial contact (x0, y0, and t0) which helps compute more
13−-- complicated gestures.
14touches : Signal [Touch]
16touches : Signal [Touch]
15
17
16-- The last position that was tapped. Default value is `{x=0,y=0}`.
18-- The last position that was tapped. Default value is `{x=0,y=0}`.