{"id":255,"date":"2009-04-16T14:33:44","date_gmt":"2009-04-16T21:33:44","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=1175"},"modified":"2009-04-16T14:33:44","modified_gmt":"2009-04-16T21:33:44","slug":"drawing-gears","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=255","title":{"rendered":"Drawing Gears"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nconst TWO_PI:Number=Math.PI*2;\r\n\/\/ x, y, max radius, notch number\r\ndrawVerts(calcGear(200, 200, 50, 9));\r\n\r\ndrawVerts(calcGear(400, 200, 30, 3));\r\n\r\ndrawVerts(calcGear(300, 350, 30, 5));\r\n\r\ndrawVerts(calcGear(400,400, 30, 2));\r\n\r\nfunction calcGear(x:Number, y:Number, maxRad:Number, s:int):Array {\r\n\tvar verts:Array = new Array();\r\n\tvar step:Number=TWO_PI \/ (s * 4);\r\n\tvar mod:Number=0;\r\n\tfor (var i:Number = 0; i&lt;=TWO_PI; i+=step) {\r\n\t\tvar r:Number = (int(mod)%2+1) * maxRad;\r\n\t\tmod+=.5;\r\n\t\tverts.push(x + r * Math.cos(i));\r\n\t\tverts.push(y + r * Math.sin(i));\r\n\t}\r\n\treturn verts;\r\n}\r\n\r\n\/\/ could  use draw path here instead;\r\nfunction drawVerts(verts:Array):void{\r\n\tgraphics.lineStyle(0,0x000000);\r\n\tgraphics.moveTo(verts&#x5B;0], verts&#x5B;1]);\r\n\tfor (var i:int = 2; i&lt;verts.length; i+=2) {\r\n\t\tgraphics.lineTo(verts&#x5B;i], verts&#x5B;i + 1]);\r\n\t}\r\n\tgraphics.lineTo(verts&#x5B;0], verts&#x5B;1]);\r\n}\r\n<\/pre>\n<p>Needed to draw some gear shapes today&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>const TWO_PI:Number=Math.PI*2; \/\/ x, y, max radius, notch number drawVerts(calcGear(200, 200, 50, 9)); drawVerts(calcGear(400, 200, 30, 3)); drawVerts(calcGear(300, 350, 30, 5)); drawVerts(calcGear(400,400, 30, 2)); function calcGear(x:Number, y:Number, maxRad:Number, s:int):Array { var verts:Array = new Array(); var step:Number=TWO_PI \/ (s * 4); var mod:Number=0; for (var i:Number = 0; i&lt;=TWO_PI; i+=step) { var r:Number = (int(mod)%2+1) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[3,4],"class_list":["post-255","post","type-post","status-publish","format-standard","hentry","category-graphics","tag-actionscript","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/255","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=255"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/255\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}