@@ -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]