{"id":164,"date":"2009-01-22T00:00:16","date_gmt":"2009-01-22T07:00:16","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=571"},"modified":"2009-01-22T00:00:16","modified_gmt":"2009-01-22T07:00:16","slug":"playing-with-curves-pointpolar","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=164","title":{"rendered":"Playing with Curves Point.polar()"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n&#x5B;SWF(width=600, height=500, backgroundColor=0x000000, frameRate=30)]\r\nvar points:Array = new Array();\r\nvar index:int = -1;\r\nfunction polar(thetaInc:Number, radius:Number):Point{\r\n\tindex++;\r\n\tif (!points&#x5B;index]) points&#x5B;index] = 0;\r\n\treturn Point.polar(radius, points&#x5B;index] += thetaInc);\r\n}\r\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\r\n\/\/ test it out:\r\n \r\nvar canvas:BitmapData = new BitmapData(600, 500, false, 0xFFFFFF);\r\n \r\naddChild(new Bitmap(canvas, &quot;auto&quot;, true));\r\n\r\nvar p0:Point = new Point(80, 100);\r\nvar p1:Point = new Point(270, 100);\r\nvar p2:Point = new Point(480, 40);\r\nvar p3:Point = new Point(170, 180);\r\nvar p4:Point = new Point(430, 300);\r\n\r\naddEventListener(Event.ENTER_FRAME, onLoop);\r\nfunction onLoop(evt:Event):void {\r\n\tfor (var i:int= 0; i&lt;100; i++){\r\n\t\t\r\n\t\t\/\/ reset index;\r\n\t\tindex = -1;\r\n\t\t\r\n        p0 = p0.add(polar(.2, 4).add(polar(-.4,2).add(polar(.05, 1))));\r\n\t    canvas.setPixel(p0.x, p0.y, 0x000000);\r\n\t\r\n\t    p1 = p1.add(polar(.1, 2).add(polar(-.2, 2).add(polar(.03, 1).add(polar(-.01,.5)))));\r\n\t    canvas.setPixel(p1.x, p1.y, 0x000000);\r\n\t  \r\n\t    p2 = p2.add(polar(.08, 3 ).add(polar(-.2, -12).add(polar(2, 10))));\r\n\t    canvas.setPixel(p2.x, p2.y, 0x000000);\r\n\t  \r\n\t    p3 = p3.add(polar(.08, 7).add(polar(-.2, -12).add(polar(2, 11))));\r\n\t    canvas.setPixel(p3.x, p3.y, 0x000000);\r\n\t   \r\n\t    p4 = p4.add(polar(.025, 2).add(polar(-.05,1)));\r\n\t    canvas.setPixel(p4.x, p4.y, 0x000000);\r\n\t}\r\n}\r\n<\/pre>\n<p>The polar() function is the real trick here&#8230; the rest of the code just uses it to draw this:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/actionsnippet.com\/imgs\/some_curves.jpg\" \/><\/p>\n<p>The Point.polar() function is just a conversion from polar to cartesian coords:<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nx = radius * Math.cos(theta);\r\ny = radius * Math.sin(theta);\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#x5B;SWF(width=600, height=500, backgroundColor=0x000000, frameRate=30)] var points:Array = new Array(); var index:int = -1; function polar(thetaInc:Number, radius:Number):Point{ index++; if (!points&#x5B;index]) points&#x5B;index] = 0; return Point.polar(radius, points&#x5B;index] += thetaInc); } \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ \/\/ test it out: var canvas:BitmapData = new BitmapData(600, 500, false, 0xFFFFFF); addChild(new Bitmap(canvas, &quot;auto&quot;, true)); var p0:Point = new Point(80, 100); var p1:Point = new [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,26],"tags":[3,4],"class_list":["post-164","post","type-post","status-publish","format-standard","hentry","category-motion","category-setpixel","tag-actionscript","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/164","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=164"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/164\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}