on fa9d3bf help sign in
elk/libraries/Graphics/Geometry.elm
30 lines 664 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
9type Path = [(Float,Float)]
11path ps = ps
12segment p1 p2 = [p1,p2]
14type Shape = [(Float,Float)]
16polygon points = points
18rect w h = [ (0-w/2,0-h/2), (0-w/2,h/2), (w/2,h/2), (w/2,0-h/2) ]
20oval w h =
21 let n = 50
22 f i = (w/2 * Math.cos (2*Math.pi/n * i), h/2 * Math.sin (2*Math.pi/n * i))
23 in map f [0..n-1]
25circle r = oval (2*r) (2*r)
27ngon n r =
28 let m = toFloat n
29 f i = ( r * Math.cos (2*Math.pi/m * i), r * Math.sin (2*Math.pi/m * i))
30 in map f [0..n-1]