on master help sign in
Get Graphics/ compiling!
commitfc6ce753448d8813451af3aff5bf595643101369 authorEvan Czaplicki <info@elm-lang.org> dateSat 27 Jul 2013, 13:06 (13 years ago) parentd6acea8
3 files changed+37−32
libraries/Graphics/Collage.elm+24−22 libraries/Graphics/Element.elm+1−1 libraries/Graphics/Input.elm+12−9
libraries/Graphics/Collage.elm+24−22
@@ -1,13 +1,15 @@
11
22module Graphics.Collage where
33
4+import open Basics
45import List
5−import Basics (toFloat)
6−import Either
7−import Matrix2D as Matrix
6+import Either (Either, Left, Right)
7+import Matrix2D (Matrix2D, identity)
88import Native.Graphics.Collage as Native
9−import Graphics.Element (Element)
10−import Color
9+import Graphics.Element (Element, Three, Pos, ElementPrim, Properties)
10+import Color (Color, black, Gradient)
11+import Maybe (Maybe)
12+import JavaScript (JSString)
1113
1214type Form = {
1315 theta : Float,
@@ -49,7 +51,7 @@ type LineStyle = {
4951-- { defaultLine | width <- 10 }
5052defaultLine : LineStyle
5153defaultLine = {
52− color = Color.black,
54+ color = black,
5355 width = 1,
5456 cap = Flat,
5557 join = Sharp 10,
@@ -79,7 +81,7 @@ data BasicForm
7981form : BasicForm -> Form
8082form f = { theta=0, scale=1, x=0, y=0, alpha=1, form=f }
8183
82−fill style shape = form (FShape (Either.Right style) shape)
84+fill style shape = form (FShape (Right style) shape)
8385
8486-- Create a filled in shape.
8587filled : Color -> Shape -> Form
@@ -96,7 +98,7 @@ gradient grad shape = fill (Gradient grad) shape
9698
9799-- Outline a shape with a given line style.
98100outlined : LineStyle -> Shape -> Form
99−outlined style shape = form (FShape (Either.Left style) shape)
101+outlined style shape = form (FShape (Left style) shape)
100102
101103-- Trace a path with a given line style.
102104traced : LineStyle -> Path -> Form
@@ -116,7 +118,7 @@ toForm e = form (FElement e)
116118-- Flatten many forms into a single `Form`. This lets you move and rotate them
117119-- as a single unit, making it possible to build small, modular components.
118120group : [Form] -> Form
119−group fs = form (FGroup Matrix.identity fs)
121+group fs = form (FGroup identity fs)
120122
121123-- Flatten many forms into a single `Form` and then apply a matrix
122124-- transformation.
@@ -162,11 +164,11 @@ collage = Native.collage
162164type Path = [(Float,Float)]
163165
164166-- Create a path that follows a sequence of points.
165−path : [(number,number)] -> Path
167+path : [(Float,Float)] -> Path
166168path ps = ps
167169
168170-- Create a path along a given line segment.
169−segment : (number,number) -> (number,number) -> Path
171+segment : (Float,Float) -> (Float,Float) -> Path
170172segment p1 p2 = [p1,p2]
171173
172174type Shape = [(Float,Float)]
@@ -174,31 +176,31 @@ type Shape = [(Float,Float)]
174176-- Create an arbitrary polygon by specifying its corners in order.
175177-- `polygon` will automatically close all shapes, so the given list
176178-- of points does not need to start and end with the same position.
177−polygon : [(number,number)] -> Shape
179+polygon : [(Float,Float)] -> Shape
178180polygon points = points
179181
180182-- A rectangle with a given width and height.
181−rect : number -> number -> Shape
183+rect : Float -> Float -> Shape
182184rect w h = let hw = w/2
183185 hh = h/2
184186 in [ (0-hw,0-hh), (0-hw,hh), (hw,hh), (hw,0-hh) ]
185187
186188-- A square with a given edge length.
187−square : number -> Shape
189+square : Float -> Shape
188190square n = rect n n
189191
190192-- An oval with a given width and height.
191−oval : number -> number -> Shape
193+oval : Float -> Float -> Shape
192194oval w h =
193195 let n = 50
194− t = 2 * Math.PI / n
196+ t = 2 * pi / n
195197 hw = w/2
196198 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))
198200 in List.map f [0..n-1]
199201
200202-- A circle with a given radius.
201−circle : number -> Shape
203+circle : Float -> Shape
202204circle r = oval (2*r) (2*r)
203205
204206-- A regular polygon with N sides. The first argument specifies the number
@@ -206,9 +208,9 @@ circle r = oval (2*r) (2*r)
206208-- 30 you would say:
207209--
208210-- ngon 5 30
209−ngon : Int -> number -> Shape
211+ngon : Int -> Float -> Shape
210212ngon n r =
211213 let m = toFloat n
212− t = 2 * Math.PI / m
213− f i = ( r * Math.cos (t*i), r * Math.sin (t*i) )
214− in List.map f [0..n-1]
214+ t = 2 * pi / m
215+ f i = ( r * cos (t*i), r * sin (t*i) )
216+ in List.map f [0..m-1]
libraries/Graphics/Element.elm+1−1
@@ -9,7 +9,7 @@ module Graphics.Element (widthOf, heightOf, sizeOf,
99 midLeft, midRight, midTop, midBottom, middleAt,
1010 topLeftAt, topRightAt, bottomLeftAt, bottomRightAt,
1111 midLeftAt, midRightAt, midTopAt, midBottomAt,
12− spacer, newElement
12+ spacer, newElement, Three, Pos, ElementPrim, Properties
1313 ) where
1414
1515import open Basics
libraries/Graphics/Input.elm+12−9
@@ -4,7 +4,10 @@ module Graphics.Input where
44import Signal (lift,dropRepeats)
55import Native.Graphics.Input as Native
66import 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)
811
912id x = x
1013
@@ -24,7 +27,7 @@ buttons = Native.buttons
2427-- a signal of units. This signal triggers whenever the button is pressed.
2528button : String -> (Element, Signal ())
2629button txt =
27− let pool = N.buttons ()
30+ let pool = Native.buttons ()
2831 in (pool.button () txt, pool.events)
2932
3033-- Create a group of custom buttons.
@@ -45,7 +48,7 @@ customButtons = Native.customButtons
4548-- a signal of units. This signal triggers whenever the button is pressed.
4649customButton : Element -> Element -> Element -> (Element, Signal ())
4750customButton up hover down =
48− let pool = N.customButtons ()
51+ let pool = Native.customButtons ()
4952 in (pool.customButton () up hover down, pool.events)
5053
5154-- Create a group of checkboxes.
@@ -68,7 +71,7 @@ checkboxes = Native.checkboxes
6871-- The boolean signal represents the current state of the checkbox.
6972checkbox : Bool -> (Signal Element, Signal Bool)
7073checkbox b =
71− let cbs = N.checkboxes b
74+ let cbs = Native.checkboxes b
7275 in (lift (cbs.box id) cbs.events, cbs.events)
7376
7477hoverables : a -> { events : Signal a,
@@ -77,7 +80,7 @@ hoverables = Native.hoverables
7780
7881hoverable : Element -> (Element, Signal Bool)
7982hoverable elem =
80− let pool = N.hoverables False
83+ let pool = Native.hoverables False
8184 in (pool.hoverable id elem, pool.events)
8285
8386-- Represents the current state of a text field. The `string` represents the
@@ -116,7 +119,7 @@ emptyFieldState = { string="", selectionStart=0, selectionEnd=0 }
116119-- content of the field.
117120field : String -> (Signal Element, Signal String)
118121field placeHolder =
119− let tfs = N.fields emptyFieldState
122+ let tfs = Native.fields emptyFieldState
120123 changes = dropRepeats tfs.events
121124 in (lift (tfs.field id placeHolder) changes,
122125 dropRepeats (lift .string changes))
@@ -124,7 +127,7 @@ field placeHolder =
124127-- Same as `field` but the UI element blocks out each characters.
125128password : String -> (Signal Element, Signal String)
126129password placeHolder =
127− let tfs = N.passwords emptyFieldState
130+ let tfs = Native.passwords emptyFieldState
128131 changes = dropRepeats tfs.events
129132 in (lift (tfs.field id placeHolder) changes,
130133 dropRepeats (lift .string changes))
@@ -134,7 +137,7 @@ password placeHolder =
134137-- get a custom keyboard with an `@` and `.com` button.
135138email : String -> (Signal Element, Signal String)
136139email placeHolder =
137− let tfs = N.emails emptyFieldState
140+ let tfs = Native.emails emptyFieldState
138141 changes = dropRepeats tfs.events
139142 in (lift (tfs.field id placeHolder) changes,
140143 dropRepeats (lift .string changes))
@@ -150,4 +153,4 @@ dropDown = Native.dropDown
150153-- signal of strings represents the string that is currently selected.
151154stringDropDown : [String] -> (Signal Element, Signal String)
152155stringDropDown strs =
153− N.dropDown (List.map (\s -> (s,s)) strs)
156+ Native.dropDown (List.map (\s -> (s,s)) strs)