on master help sign in
Fix oval and ngon. (It's PI, not pi!)
86a0a90evancz
libraries/Graphics/Geometry.elm+7−2
@@ -5,6 +5,7 @@
5module Graphics.Geometry where
5module Graphics.Geometry where
6
6
7import List
7import List
8+import Native.Utils (toFloat)
8
9
9type Path = [(Float,Float)]
10type Path = [(Float,Float)]
10
11
@@ -19,12 +20,16 @@ rect w h = [ (0-w/2,0-h/2), (0-w/2,h/2), (w/2,h/2), (w/2,0-h/2) ]
19
20
20oval w h =
21oval w h =
21 let n = 50
22 let n = 50
23+ t = 2 * Math.PI / n
24+ hw = w/2
25+ hh = h/2
22− f i = (w/2 * Math.cos (2*Math.pi/n * i), h/2 * Math.sin (2*Math.pi/n * i))
26+ f i = (hw * Math.cos (t*i), hh * Math.sin (t*i))
23 in map f [0..n-1]
27 in map f [0..n-1]
24
28
25circle r = oval (2*r) (2*r)
29circle r = oval (2*r) (2*r)
26
30
27ngon n r =
31ngon n r =
28 let m = toFloat n
32 let m = toFloat n
33+ t = 2 * Math.PI / m
29− f i = ( r * Math.cos (2*Math.pi/m * i), r * Math.sin (2*Math.pi/m * i))
34+ f i = ( r * Math.cos (t*i), r * Math.sin (t*i) )
30 in map f [0..n-1]
35 in map f [0..n-1]
libraries/Native/Utils.js+2−1
@@ -122,6 +122,7 @@ Elm.Native.Utils = function(elm) {
122 guid: guid,
122 guid: guid,
123 max : F2(max),
123 max : F2(max),
124 min : F2(min),
124 min : F2(min),
125− htmlHeight: F2(htmlHeight)
125+ htmlHeight: F2(htmlHeight),
126+ toFloat: function(x){return x}
126 };
127 };
127};
128};
runtime/Render/Collage.js+1
@@ -150,6 +150,7 @@ function collageForms(w,h,forms) {
150 function redo() { renderForms(this,ctx,forms); }
150 function redo() { renderForms(this,ctx,forms); }
151 if (canvas.getContext) {
151 if (canvas.getContext) {
152 var ctx = canvas.getContext('2d');
152 var ctx = canvas.getContext('2d');
153+ ctx.translate(w/2, h/2);
153 renderForms(redo,ctx,forms);
154 renderForms(redo,ctx,forms);
154 return canvas;
155 return canvas;
155 }
156 }