on master help sign in
Get Graphics/ compiling!
fc6ce75Evan Czaplicki
libraries/Graphics/Collage.elm+24−22
@@ -1,13 +1,15 @@
1
1
2module Graphics.Collage where
2module Graphics.Collage where
3
3
4+import open Basics
4import List
5import List
5−import Basics (toFloat)
6+import Either (Either, Left, Right)
6−import Either
7−import Matrix2D as Matrix
7+import Matrix2D (Matrix2D, identity)
8import Native.Graphics.Collage as Native
8import Native.Graphics.Collage as Native
9−import Graphics.Element (Element)
9+import Graphics.Element (Element, Three, Pos, ElementPrim, Properties)
10−import Color
10+import Color (Color, black, Gradient)
11+import Maybe (Maybe)
12+import JavaScript (JSString)
11
13
12type Form = {
14type Form = {
13 theta : Float,
15 theta : Float,
@@ -49,7 +51,7 @@ type LineStyle = {
49-- { defaultLine | width <- 10 }
51-- { defaultLine | width <- 10 }
50defaultLine : LineStyle
52defaultLine : LineStyle
51defaultLine = {
53defaultLine = {
52− color = Color.black,
54+ color = black,
53 width = 1,
55 width = 1,
54 cap = Flat,
56 cap = Flat,
55 join = Sharp 10,
57 join = Sharp 10,
@@ -79,7 +81,7 @@ data BasicForm
79form : BasicForm -> Form
81form : BasicForm -> Form
80form f = { theta=0, scale=1, x=0, y=0, alpha=1, form=f }
82form f = { theta=0, scale=1, x=0, y=0, alpha=1, form=f }
81
83
82−fill style shape = form (FShape (Either.Right style) shape)
84+fill style shape = form (FShape (Right style) shape)
83
85
84-- Create a filled in shape.
86-- Create a filled in shape.
85filled : Color -> Shape -> Form
87filled : Color -> Shape -> Form
@@ -96,7 +98,7 @@ gradient grad shape = fill (Gradient grad) shape
96
98
97-- Outline a shape with a given line style.
99-- Outline a shape with a given line style.
98outlined : LineStyle -> Shape -> Form
100outlined : LineStyle -> Shape -> Form
99−outlined style shape = form (FShape (Either.Left style) shape)
101+outlined style shape = form (FShape (Left style) shape)
100
102
101-- Trace a path with a given line style.
103-- Trace a path with a given line style.
102traced : LineStyle -> Path -> Form
104traced : LineStyle -> Path -> Form
@@ -116,7 +118,7 @@ toForm e = form (FElement e)
116-- Flatten many forms into a single `Form`. This lets you move and rotate them
118-- Flatten many forms into a single `Form`. This lets you move and rotate them
117-- as a single unit, making it possible to build small, modular components.
119-- as a single unit, making it possible to build small, modular components.
118group : [Form] -> Form
120group : [Form] -> Form
119−group fs = form (FGroup Matrix.identity fs)
121+group fs = form (FGroup identity fs)
120
122
121-- Flatten many forms into a single `Form` and then apply a matrix
123-- Flatten many forms into a single `Form` and then apply a matrix
122-- transformation.
124-- transformation.
@@ -162,11 +164,11 @@ collage = Native.collage
162type Path = [(Float,Float)]
164type Path = [(Float,Float)]
163
165
164-- Create a path that follows a sequence of points.
166-- Create a path that follows a sequence of points.
165−path : [(number,number)] -> Path
167+path : [(Float,Float)] -> Path
166path ps = ps
168path ps = ps
167
169
168-- Create a path along a given line segment.
170-- Create a path along a given line segment.
169−segment : (number,number) -> (number,number) -> Path
171+segment : (Float,Float) -> (Float,Float) -> Path
170segment p1 p2 = [p1,p2]
172segment p1 p2 = [p1,p2]
171
173
172type Shape = [(Float,Float)]
174type Shape = [(Float,Float)]
@@ -174,31 +176,31 @@ type Shape = [(Float,Float)]
174-- Create an arbitrary polygon by specifying its corners in order.
176-- Create an arbitrary polygon by specifying its corners in order.
175-- `polygon` will automatically close all shapes, so the given list
177-- `polygon` will automatically close all shapes, so the given list
176-- of points does not need to start and end with the same position.
178-- of points does not need to start and end with the same position.
177−polygon : [(number,number)] -> Shape
179+polygon : [(Float,Float)] -> Shape
178polygon points = points
180polygon points = points
179
181
180-- A rectangle with a given width and height.
182-- A rectangle with a given width and height.
181−rect : number -> number -> Shape
183+rect : Float -> Float -> Shape
182rect w h = let hw = w/2
184rect w h = let hw = w/2
183 hh = h/2
185 hh = h/2
184 in [ (0-hw,0-hh), (0-hw,hh), (hw,hh), (hw,0-hh) ]
186 in [ (0-hw,0-hh), (0-hw,hh), (hw,hh), (hw,0-hh) ]
185
187
186-- A square with a given edge length.
188-- A square with a given edge length.
187−square : number -> Shape
189+square : Float -> Shape
188square n = rect n n
190square n = rect n n
189
191
190-- An oval with a given width and height.
192-- An oval with a given width and height.
191−oval : number -> number -> Shape
193+oval : Float -> Float -> Shape
192oval w h =
194oval w h =
193 let n = 50
195 let n = 50
194− t = 2 * Math.PI / n
196+ t = 2 * pi / n
195 hw = w/2
197 hw = w/2
196 hh = h/2
198 hh = h/2
197− f i = (hw * Math.cos (t*i), hh * Math.sin (t*i))
199+ f i = (hw * cos (t*i), hh * sin (t*i))
198 in List.map f [0..n-1]
200 in List.map f [0..n-1]
199
201
200-- A circle with a given radius.
202-- A circle with a given radius.
201−circle : number -> Shape
203+circle : Float -> Shape
202circle r = oval (2*r) (2*r)
204circle r = oval (2*r) (2*r)
203
205
204-- A regular polygon with N sides. The first argument specifies the number
206-- A regular polygon with N sides. The first argument specifies the number
@@ -206,9 +208,9 @@ circle r = oval (2*r) (2*r)
206-- 30 you would say:
208-- 30 you would say:
207--
209--
208-- ngon 5 30
210-- ngon 5 30
209−ngon : Int -> number -> Shape
211+ngon : Int -> Float -> Shape
210ngon n r =
212ngon n r =
211 let m = toFloat n
213 let m = toFloat n
212− t = 2 * Math.PI / m
214+ t = 2 * pi / m
213− f i = ( r * Math.cos (t*i), r * Math.sin (t*i) )
215+ f i = ( r * cos (t*i), r * sin (t*i) )
214− in List.map f [0..n-1]
216+ in List.map f [0..m-1]
libraries/Graphics/Element.elm+1−1
@@ -9,7 +9,7 @@ module Graphics.Element (widthOf, heightOf, sizeOf,
9 midLeft, midRight, midTop, midBottom, middleAt,
9 midLeft, midRight, midTop, midBottom, middleAt,
10 topLeftAt, topRightAt, bottomLeftAt, bottomRightAt,
10 topLeftAt, topRightAt, bottomLeftAt, bottomRightAt,
11 midLeftAt, midRightAt, midTopAt, midBottomAt,
11 midLeftAt, midRightAt, midTopAt, midBottomAt,
12− spacer, newElement
12+ spacer, newElement, Three, Pos, ElementPrim, Properties
13 ) where
13 ) where
14
14
15import open Basics
15import open Basics
libraries/Graphics/Input.elm+12−9
@@ -4,7 +4,10 @@ module Graphics.Input where
4import Signal (lift,dropRepeats)
4import Signal (lift,dropRepeats)
5import Native.Graphics.Input as Native
5import Native.Graphics.Input as Native
6import List
6import List
7−import Graphics.Element (Element)
7+import Graphics.Element (Element, Three, Pos, ElementPrim, Properties)
8+import Color (Color)
9+import Maybe (Maybe)
10+import JavaScript (JSString)
8
11
9id x = x
12id x = x
10
13
@@ -24,7 +27,7 @@ buttons = Native.buttons
24-- a signal of units. This signal triggers whenever the button is pressed.
27-- a signal of units. This signal triggers whenever the button is pressed.
25button : String -> (Element, Signal ())
28button : String -> (Element, Signal ())
26button txt =
29button txt =
27− let pool = N.buttons ()
30+ let pool = Native.buttons ()
28 in (pool.button () txt, pool.events)
31 in (pool.button () txt, pool.events)
29
32
30-- Create a group of custom buttons.
33-- Create a group of custom buttons.
@@ -45,7 +48,7 @@ customButtons = Native.customButtons
45-- a signal of units. This signal triggers whenever the button is pressed.
48-- a signal of units. This signal triggers whenever the button is pressed.
46customButton : Element -> Element -> Element -> (Element, Signal ())
49customButton : Element -> Element -> Element -> (Element, Signal ())
47customButton up hover down =
50customButton up hover down =
48− let pool = N.customButtons ()
51+ let pool = Native.customButtons ()
49 in (pool.customButton () up hover down, pool.events)
52 in (pool.customButton () up hover down, pool.events)
50
53
51-- Create a group of checkboxes.
54-- Create a group of checkboxes.
@@ -68,7 +71,7 @@ checkboxes = Native.checkboxes
68-- The boolean signal represents the current state of the checkbox.
71-- The boolean signal represents the current state of the checkbox.
69checkbox : Bool -> (Signal Element, Signal Bool)
72checkbox : Bool -> (Signal Element, Signal Bool)
70checkbox b =
73checkbox b =
71− let cbs = N.checkboxes b
74+ let cbs = Native.checkboxes b
72 in (lift (cbs.box id) cbs.events, cbs.events)
75 in (lift (cbs.box id) cbs.events, cbs.events)
73
76
74hoverables : a -> { events : Signal a,
77hoverables : a -> { events : Signal a,
@@ -77,7 +80,7 @@ hoverables = Native.hoverables
77
80
78hoverable : Element -> (Element, Signal Bool)
81hoverable : Element -> (Element, Signal Bool)
79hoverable elem =
82hoverable elem =
80− let pool = N.hoverables False
83+ let pool = Native.hoverables False
81 in (pool.hoverable id elem, pool.events)
84 in (pool.hoverable id elem, pool.events)
82
85
83-- Represents the current state of a text field. The `string` represents the
86-- Represents the current state of a text field. The `string` represents the
@@ -116,7 +119,7 @@ emptyFieldState = { string="", selectionStart=0, selectionEnd=0 }
116-- content of the field.
119-- content of the field.
117field : String -> (Signal Element, Signal String)
120field : String -> (Signal Element, Signal String)
118field placeHolder =
121field placeHolder =
119− let tfs = N.fields emptyFieldState
122+ let tfs = Native.fields emptyFieldState
120 changes = dropRepeats tfs.events
123 changes = dropRepeats tfs.events
121 in (lift (tfs.field id placeHolder) changes,
124 in (lift (tfs.field id placeHolder) changes,
122 dropRepeats (lift .string changes))
125 dropRepeats (lift .string changes))
@@ -124,7 +127,7 @@ field placeHolder =
124-- Same as `field` but the UI element blocks out each characters.
127-- Same as `field` but the UI element blocks out each characters.
125password : String -> (Signal Element, Signal String)
128password : String -> (Signal Element, Signal String)
126password placeHolder =
129password placeHolder =
127− let tfs = N.passwords emptyFieldState
130+ let tfs = Native.passwords emptyFieldState
128 changes = dropRepeats tfs.events
131 changes = dropRepeats tfs.events
129 in (lift (tfs.field id placeHolder) changes,
132 in (lift (tfs.field id placeHolder) changes,
130 dropRepeats (lift .string changes))
133 dropRepeats (lift .string changes))
@@ -134,7 +137,7 @@ password placeHolder =
134-- get a custom keyboard with an `@` and `.com` button.
137-- get a custom keyboard with an `@` and `.com` button.
135email : String -> (Signal Element, Signal String)
138email : String -> (Signal Element, Signal String)
136email placeHolder =
139email placeHolder =
137− let tfs = N.emails emptyFieldState
140+ let tfs = Native.emails emptyFieldState
138 changes = dropRepeats tfs.events
141 changes = dropRepeats tfs.events
139 in (lift (tfs.field id placeHolder) changes,
142 in (lift (tfs.field id placeHolder) changes,
140 dropRepeats (lift .string changes))
143 dropRepeats (lift .string changes))
@@ -150,4 +153,4 @@ dropDown = Native.dropDown
150-- signal of strings represents the string that is currently selected.
153-- signal of strings represents the string that is currently selected.
151stringDropDown : [String] -> (Signal Element, Signal String)
154stringDropDown : [String] -> (Signal Element, Signal String)
152stringDropDown strs =
155stringDropDown strs =
153− N.dropDown (List.map (\s -> (s,s)) strs)
156+ Native.dropDown (List.map (\s -> (s,s)) strs)