@@ -1,13 +1,15 @@
2module Graphics.Collage where
2module Graphics.Collage where
5−import Basics (toFloat)
6+import Either (Either, Left, Right)
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)
12+import JavaScript (JSString)
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 }
82−fill style shape = form (FShape (Either.Right style) shape)
84+fill style shape = form (FShape (Right style) shape)
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
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)
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)
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)]
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
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]
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
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
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) ]
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
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
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]
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)
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:
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]