on 294fdfd help sign in
elk/libraries/Graphics/Geometry.elm
35 lines 727 B history raw
1-- Paths and Shapes.
2-- These structures are purely geometric forms, no colors or styles.
3-- Could be the basis of some cool geometry stuff :)
5module Graphics.Geometry where
7import List
8import Native.Utils (toFloat)
10type Path = [(Float,Float)]
12path ps = ps
13segment p1 p2 = [p1,p2]
15type Shape = [(Float,Float)]
17polygon points = points
19rect w h = [ (0-w/2,0-h/2), (0-w/2,h/2), (w/2,h/2), (w/2,0-h/2) ]
21oval w h =
22 let n = 50
23 t = 2 * Math.PI / n
24 hw = w/2
25 hh = h/2
26 f i = (hw * Math.cos (t*i), hh * Math.sin (t*i))
27 in map f [0..n-1]
29circle r = oval (2*r) (2*r)
31ngon n r =
32 let m = toFloat n
33 t = 2 * Math.PI / m
34 f i = ( r * Math.cos (t*i), r * Math.sin (t*i) )
35 in map f [0..n-1]