on master help sign in
Get Graphics/ libraries closer to compiling
5234d6dEvan Czaplicki
libraries/Graphics/Collage.elm+13−12
@@ -2,11 +2,11 @@
2module Graphics.Collage where
2module Graphics.Collage where
3
3
4import List
4import List
5−import Native.Utils (toFloat)
5+import Basics (toFloat)
6import Either
6import Either
7−import Native.Matrix2D as Matrix
7+import Matrix2D as Matrix
8−import Native.Graphics.Collage as N
8+import Native.Graphics.Collage as Native
9−import Graphics.Element
9+import Graphics.Element (Element)
10import Color
10import Color
11
11
12type Form = {
12type Form = {
@@ -156,16 +156,17 @@ opacity a f = { f | alpha <- a }
156-- A collage is a collection of 2D forms. There are no strict positioning
156-- A collage is a collection of 2D forms. There are no strict positioning
157-- relationships between forms, so you are free to do all kinds of 2D graphics.
157-- relationships between forms, so you are free to do all kinds of 2D graphics.
158collage : Int -> Int -> [Form] -> Element
158collage : Int -> Int -> [Form] -> Element
159+collage = Native.collage
159
160
160
161
161type Path = [(Float,Float)]
162type Path = [(Float,Float)]
162
163
163-- Create a path that follows a sequence of points.
164-- Create a path that follows a sequence of points.
164−path : [(Number a,Number a)] -> Path
165+path : [(number,number)] -> Path
165path ps = ps
166path ps = ps
166
167
167-- Create a path along a given line segment.
168-- Create a path along a given line segment.
168−segment : (Number a,Number a) -> (Number a,Number a) -> Path
169+segment : (number,number) -> (number,number) -> Path
169segment p1 p2 = [p1,p2]
170segment p1 p2 = [p1,p2]
170
171
171type Shape = [(Float,Float)]
172type Shape = [(Float,Float)]
@@ -173,21 +174,21 @@ type Shape = [(Float,Float)]
173-- Create an arbitrary polygon by specifying its corners in order.
174-- Create an arbitrary polygon by specifying its corners in order.
174-- `polygon` will automatically close all shapes, so the given list
175-- `polygon` will automatically close all shapes, so the given list
175-- of points does not need to start and end with the same position.
176-- of points does not need to start and end with the same position.
176−polygon : [(Number a,Number a)] -> Shape
177+polygon : [(number,number)] -> Shape
177polygon points = points
178polygon points = points
178
179
179-- A rectangle with a given width and height.
180-- A rectangle with a given width and height.
180−rect : Number a -> Number a -> Shape
181+rect : number -> number -> Shape
181rect w h = let hw = w/2
182rect w h = let hw = w/2
182 hh = h/2
183 hh = h/2
183 in [ (0-hw,0-hh), (0-hw,hh), (hw,hh), (hw,0-hh) ]
184 in [ (0-hw,0-hh), (0-hw,hh), (hw,hh), (hw,0-hh) ]
184
185
185-- A square with a given edge length.
186-- A square with a given edge length.
186−square : Number a -> Shape
187+square : number -> Shape
187square n = rect n n
188square n = rect n n
188
189
189-- An oval with a given width and height.
190-- An oval with a given width and height.
190−oval : Number a -> Number a -> Shape
191+oval : number -> number -> Shape
191oval w h =
192oval w h =
192 let n = 50
193 let n = 50
193 t = 2 * Math.PI / n
194 t = 2 * Math.PI / n
@@ -197,7 +198,7 @@ oval w h =
197 in List.map f [0..n-1]
198 in List.map f [0..n-1]
198
199
199-- A circle with a given radius.
200-- A circle with a given radius.
200−circle : Number a -> Shape
201+circle : number -> Shape
201circle r = oval (2*r) (2*r)
202circle r = oval (2*r) (2*r)
202
203
203-- A regular polygon with N sides. The first argument specifies the number
204-- A regular polygon with N sides. The first argument specifies the number
@@ -205,7 +206,7 @@ circle r = oval (2*r) (2*r)
205-- 30 you would say:
206-- 30 you would say:
206--
207--
207-- ngon 5 30
208-- ngon 5 30
208−ngon : Int -> Number a -> Shape
209+ngon : Int -> number -> Shape
209ngon n r =
210ngon n r =
210 let m = toFloat n
211 let m = toFloat n
211 t = 2 * Math.PI / m
212 t = 2 * Math.PI / m
libraries/Graphics/Element.elm+24−21
@@ -12,11 +12,12 @@ module Graphics.Element (widthOf, heightOf, sizeOf,
12 spacer, newElement
12 spacer, newElement
13 ) where
13 ) where
14
14
15−import Native.Utils (guid, max, htmlHeight)
15+import open Basics
16−import JavaScript as JS
16+import Native.Utils as Native
17+import open JavaScript
17import List as List
18import List as List
18−import Color
19+import Color (Color)
19−import Maybe (Just, Nothing)
20+import Maybe (Maybe, Just, Nothing)
20
21
21type Properties = {
22type Properties = {
22 id : Int,
23 id : Int,
@@ -45,18 +46,18 @@ sizeOf e = (e.props.width, e.props.height)
45
46
46-- Create an `Element` with a given width.
47-- Create an `Element` with a given width.
47width : Int -> Element -> Element
48width : Int -> Element -> Element
48−width nw e = let p = e.props
49+width nw e = let p = e.props
49− props = case e.element of
50+ props = case e.element of
50− Image _ w h _ -> {p| height <- h/w*nw }
51+ Image _ w h _ -> {p| height <- h `div` w * nw }
51− RawHtml html -> {p| height <- let (w,h) = htmlHeight nw html in h}
52+ RawHtml html -> {p| height <- let (w,h) = Native.htmlHeight nw html in h}
52− _ -> p
53+ _ -> p
53− in { element=e.element, props={props| width <- nw} }
54+ in { element=e.element, props={ props | width <- nw } }
54
55
55-- Create an `Element` with a given height.
56-- Create an `Element` with a given height.
56height : Int -> Element -> Element
57height : Int -> Element -> Element
57height nh e = let p = e.props
58height nh e = let p = e.props
58 props = case e.element of
59 props = case e.element of
59− Image _ w h _ -> {p| width <- w/h*nh }
60+ Image _ w h _ -> {p| width <- w `div` h * nh }
60 _ -> p
61 _ -> p
61 in { element=e.element, props={p| height <- nh} }
62 in { element=e.element, props={p| height <- nh} }
62
63
@@ -71,24 +72,26 @@ opacity o e = let p = e.props in { element=e.element, props={p| opacity <- o} }
71
72
72-- Create an `Element` with a given background color.
73-- Create an `Element` with a given background color.
73color : Color -> Element -> Element
74color : Color -> Element -> Element
74−color c e = let p = e.props in
75+color c e = let p = e.props in
76+ { element = e.element
75− { element=e.element, props={p| color <- Just c} }
77+ , props = { p | color <- Just c}
78+ }
76
79
77-- Create an `Element` with a tag. This lets you link directly to it.
80-- Create an `Element` with a tag. This lets you link directly to it.
78-- The element `(tag "all-about-badgers" thirdParagraph)` can be reached
81-- The element `(tag "all-about-badgers" thirdParagraph)` can be reached
79-- with a link lik this: `/facts-about-animals.elm#all-about-badgers`
82-- with a link lik this: `/facts-about-animals.elm#all-about-badgers`
80tag : String -> Element -> Element
83tag : String -> Element -> Element
81tag name e = let p = e.props in
84tag name e = let p = e.props in
82− { element=e.element, props={p| tag <- JS.fromString name} }
85+ { element=e.element, props={p | tag <- fromString name} }
83
86
84-- Create an `Element` that is a hyper-link.
87-- Create an `Element` that is a hyper-link.
85link : String -> Element -> Element
88link : String -> Element -> Element
86link href e = let p = e.props in
89link href e = let p = e.props in
87− { element=e.element, props={p| href <- JS.fromString href} }
90+ { element=e.element, props={p | href <- fromString href} }
88
91
89−emptyStr = JS.fromString ""
92+emptyStr = fromString ""
90newElement w h e =
93newElement w h e =
91− { props = Properties (guid ()) w h 1 Nothing emptyStr emptyStr (), element = e }
94+ { props = Properties (Native.guid ()) w h 1 Nothing emptyStr emptyStr (), element = e }
92
95
93data ElementPrim
96data ElementPrim
94 = Image ImageStyle Int Int JSString
97 = Image ImageStyle Int Int JSString
@@ -102,12 +105,12 @@ data ImageStyle = Plain | Fitted | Cropped (Int,Int) | Tiled
102
105
103-- Create an image given a width, height, and image source.
106-- Create an image given a width, height, and image source.
104image : Int -> Int -> String -> Element
107image : Int -> Int -> String -> Element
105−image w h src = newElement w h (Image Plain w h (JS.fromString src))
108+image w h src = newElement w h (Image Plain w h (fromString src))
106
109
107-- Create a fitted image given a width, height, and image source.
110-- Create a fitted image given a width, height, and image source.
108-- This will crop the picture to best fill the given dimensions.
111-- This will crop the picture to best fill the given dimensions.
109fittedImage : Int -> Int -> String -> Element
112fittedImage : Int -> Int -> String -> Element
110−fittedImage w h src = newElement w h (Image Fitted w h (JS.fromString src))
113+fittedImage w h src = newElement w h (Image Fitted w h (fromString src))
111
114
112-- Create a cropped image. Take a rectangle out of the picture starting
115-- Create a cropped image. Take a rectangle out of the picture starting
113-- at the given top left coordinate. If you have a 140-by-140 image,
116-- at the given top left coordinate. If you have a 140-by-140 image,
@@ -116,11 +119,11 @@ fittedImage w h src = newElement w h (Image Fitted w h (JS.fromString src))
116-- croppedImage (20,20) 100 100 "yogi.jpg"
119-- croppedImage (20,20) 100 100 "yogi.jpg"
117croppedImage : (Int,Int) -> Int -> Int -> String -> Element
120croppedImage : (Int,Int) -> Int -> Int -> String -> Element
118croppedImage pos w h src =
121croppedImage pos w h src =
119− newElement w h (Image (Cropped pos) w h (JS.fromString src))
122+ newElement w h (Image (Cropped pos) w h (fromString src))
120
123
121tiledImage : Int -> Int -> String -> Element
124tiledImage : Int -> Int -> String -> Element
122tiledImage w h src =
125tiledImage w h src =
123− newElement w h (Image Tiled w h (JS.fromString src))
126+ newElement w h (Image Tiled w h (fromString src))
124
127
125data Three = P | Z | N
128data Three = P | Z | N
126data Pos = Absolute Int | Relative Float
129data Pos = Absolute Int | Relative Float