on master help sign in
Fix oval and ngon. (It's PI, not pi!)
commit86a0a904d87f78cf4525c6c63091166b97092a42 authorevancz <info@elm-lang.org> dateFri 22 Mar 2013, 18:27 (14 years ago) parent0034b17
3 files changed+10−3
libraries/Graphics/Geometry.elm+7−2 libraries/Native/Utils.js+2−1 runtime/Render/Collage.js+1
libraries/Graphics/Geometry.elm+7−2
@@ -5,6 +5,7 @@
55module Graphics.Geometry where
66
77import List
8+import Native.Utils (toFloat)
89
910type Path = [(Float,Float)]
1011
@@ -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) ]
1920
2021oval w h =
2122 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+ 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))
2327 in map f [0..n-1]
2428
2529circle r = oval (2*r) (2*r)
2630
2731ngon n r =
2832 let m = toFloat n
29− f i = ( r * Math.cos (2*Math.pi/m * i), r * Math.sin (2*Math.pi/m * i))
33+ t = 2 * Math.PI / m
34+ f i = ( r * Math.cos (t*i), r * Math.sin (t*i) )
3035 in map f [0..n-1]
libraries/Native/Utils.js+2−1
@@ -122,6 +122,7 @@ Elm.Native.Utils = function(elm) {
122122 guid: guid,
123123 max : F2(max),
124124 min : F2(min),
125− htmlHeight: F2(htmlHeight)
125+ htmlHeight: F2(htmlHeight),
126+ toFloat: function(x){return x}
126127 };
127128};
runtime/Render/Collage.js+1
@@ -150,6 +150,7 @@ function collageForms(w,h,forms) {
150150 function redo() { renderForms(this,ctx,forms); }
151151 if (canvas.getContext) {
152152 var ctx = canvas.getContext('2d');
153+ ctx.translate(w/2, h/2);
153154 renderForms(redo,ctx,forms);
154155 return canvas;
155156 }