{"id":86,"date":"2007-06-29T06:00:22","date_gmt":"2007-06-29T11:00:22","guid":{"rendered":"http:\/\/www.pixelwit.com\/blog\/2007\/06\/29\/basic-circle-drawing-actionscript\/"},"modified":"2009-08-13T22:23:52","modified_gmt":"2009-08-14T03:23:52","slug":"basic-circle-drawing-actionscript","status":"publish","type":"post","link":"https:\/\/www.pixelwit.com\/blog\/2007\/06\/29\/basic-circle-drawing-actionscript\/","title":{"rendered":"Basic Circle Drawing ActionScript"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.pixelwit.com\/blog\/wp-content\/uploads\/2008\/08\/draw-circle.png\" alt=\"\" title=\"Draw Circle\" width=\"264\" height=\"184\" class=\"alignnone size-full wp-image-463\" \/><\/p>\n<p>Do you know how to draw a circle with ActionScript code?  It&#8217;s a handy thing to know.  You can use it to draw pie charts, equilateral polygons, analog clock faces&#8230; you can even use it to script motion.  If you use Flash for any type of drawing purposes, knowing the math behind the circles (<a title=\"Trigonometry from Wikipedia\" href=\"http:\/\/en.wikipedia.org\/wiki\/Trigonometry\">trigonometry<\/a>) can be very helpful.  In the simplest of terms, drawing a circle can be as easy as counting from 0 to 1.<!--more--><\/p>\n<p>When drawing a circle, you must place your pen on the paper somewhere to start.  Before you do this, you are at point 0 (zero), meaning you haven&#8217;t drawn anything.  And then once you finish drawing your circle you will have reached your goal.  You will have drawn 1 (one) circle.  So to draw a circle, you must go through the points between 0 and 1.<\/p>\n<p>To get from 0 to 1 will take a certain number of steps.  How many is up to you.  The number of steps determines the  number of sides your &#8220;polygon&#8221; will have.  &#8220;Polygon?&#8221; you say, &#8220;I thought we were drawing a circle.&#8221;  Well sure, theoretically.  Circles have an infinite number of points around their circumference, but we don&#8217;t have an infinite amount of time to plot out every possible point, so we&#8217;re going to approximate our circle by using a finite set of points.  When we connect these points we will have a regular polygon.  For this example I&#8217;m going to take 100 steps from 0 to 1 which will make a 100 sided polygon that is going to look a LOT like a circle.<\/p>\n<p>So far we&#8217;ve established that drawing a circle requires you to start at 0, go through &#8220;some steps&#8221;, and then you&#8217;ll end up with 1 circle.  But what are the steps?<\/p>\n<p>This is where the magic of computers comes in handy.  Trigonometry is a big hairy spider with numbers and fangs.  It&#8217;s scary, hard and not for the timid.  But if you&#8217;re brave enough to <a title=\"Take a quick course in trigonometry\" href=\"http:\/\/www.clarku.edu\/~djoyce\/trig\/\">try taming it<\/a>, you&#8217;ll come to understand it&#8217;s just a spider and easily squashed.  Whether you battle the Trigonometry monster now or later is up to you but you need to understand this simple concept, all points on the circle&#8217;s edge are measured from the center of the circle.  If you&#8217;re at the center of a big clock face and want to get to 3 o&#8217;clock you need to take a few steps to the <em>right<\/em> of center (x).  If you&#8217;re at the center of the clock and want to get to 12 o&#8217;clock you need to take a few steps <em>up<\/em> from center (y).  If you&#8217;re at center and wanted to get to 1:30, you&#8217;d take a couple steps to the <em>right<\/em> then a couple steps <em>up<\/em> (no diagonal steps).  That&#8217;s the <strong>least<\/strong> you need to know about Trigonometry to draw a circle.<\/p>\n<p>So hopefully you understand that you need to know where the center of your circle is.  For this example I&#8217;ll pick a center X 0f 250 and a center Y of 250.  The next thing you need to know is the <strong>radius<\/strong> of your circle, or as in my previous example, the number of steps it takes to get from the center of the clock to 12 o&#8217;clock.  For this example our circle will have a radius of 200 pixels.<\/p>\n<p>Believe it or not, we now have enough information to start writing some code.<\/p>\n<div class=\"codecolorer-container actionscript default\" style=\"overflow:auto;white-space:nowrap;width:100%;height:700px;\"><div class=\"actionscript codecolorer\"><span class=\"co1\">\/\/<\/span><br \/>\n<span class=\"co1\">\/\/<\/span><br \/>\n<span class=\"co1\">\/\/ As discussed above, All we need to know is<\/span><br \/>\n<span class=\"co1\">\/\/ the center of the circle, it's size and the<\/span><br \/>\n<span class=\"co1\">\/\/ number of sides we want to draw.<\/span><br \/>\n<span class=\"kw2\">function<\/span> drawCircle<span class=\"br0\">&#40;<\/span>centerX, centerY, radius, sides<span class=\"br0\">&#41;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/<\/span><br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/ Find a point for every &quot;side&quot; of the circle and<\/span><br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/ draw a line to it.<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">for<\/span><span class=\"br0\">&#40;<\/span><span class=\"kw2\">var<\/span> i=<span class=\"nu0\">0<\/span>; i<span class=\"sy0\">&lt;<\/span>=sides; i++<span class=\"br0\">&#41;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\">\/\/<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\">\/\/ Pick a point on the circle. &nbsp;The second<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\">\/\/ point on a 100 sided circle will be <\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\">\/\/ point #2 out of 100 or point 2\/100.<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\">\/\/ The point can be represented as a ratio from 0 to 1.<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw2\">var<\/span> pointRatio = i<span class=\"sy0\">\/<\/span>sides;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\">\/\/<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\">\/\/ Steps is the number of steps you have to take from<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\">\/\/ the center to reach your point on the circumference.<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\">\/\/ We'll use trigonometry to determine how many steps<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\">\/\/ to take in each direction to get to this particular point.<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw2\">var<\/span> xSteps = magicTrigFunctionX<span class=\"br0\">&#40;<\/span>pointRatio<span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw2\">var<\/span> ySteps = magicTrigFunctionY<span class=\"br0\">&#40;<\/span>pointRatio<span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\">\/\/<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\">\/\/ Once you know how many steps to take,<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\">\/\/ You need to go to the center then take the right<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\">\/\/ number of steps in each direction.<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\">\/\/ The radius determines the size of every step taken.<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw2\">var<\/span> pointX = centerX + xSteps <span class=\"sy0\">*<\/span> radius;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw2\">var<\/span> pointY = centerY + ySteps <span class=\"sy0\">*<\/span> radius;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\">\/\/<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\">\/\/ Now that you know where the point is,<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\">\/\/ draw a line to it.<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw3\">this<\/span>.<span class=\"kw3\">lineTo<\/span><span class=\"br0\">&#40;<\/span>pointX, pointY<span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><br \/>\n<span class=\"co1\">\/\/<\/span><br \/>\n<span class=\"co1\">\/\/ Set a linestyle so we can see the circle.<\/span><br \/>\n<span class=\"kw3\">lineStyle<\/span><span class=\"br0\">&#40;<\/span><span class=\"nu0\">0<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"co1\">\/\/<\/span><br \/>\n<span class=\"co1\">\/\/ Draw a 100 sided circle with a 200 pixel radius.<\/span><br \/>\ndrawCircle<span class=\"br0\">&#40;<\/span><span class=\"nu0\">250<\/span>, <span class=\"nu0\">250<\/span>, <span class=\"nu0\">200<\/span>, <span class=\"nu0\">100<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"co1\">\/\/<\/span><br \/>\n<span class=\"co1\">\/\/<\/span><\/div><\/div>\n<p>Now if you run the above code you&#8217;ll quickly see a problem.  It doesn&#8217;t work.  This is because the functions called &#8220;magicTrigFunctionX&#8221; or &#8220;magicTrigFunctionY&#8221; don&#8217;t exist.  There are comparable functions (Math.cos and Math.sin), but they&#8217;re not quite magic enough for my liking.  You see, back before there were computers, the eggheads needed something called &#8220;radians&#8221; to figure out how many steps it takes to get to each point on a circle.  So to be nice, people used to convert their nice 0-to-1 ratios to radians (big ugly irrational numbers) so the eggheads would have an easier job and quit complaining so much.<\/p>\n<p>But converting nice and neat 0-to-1-ratios to irrational numbers sounds complicated, is it?  Not really, all you need to do is multiply your 0-to-1-ratio by 2 and then multiply it by Math.PI.  Why 2?  Why Math.PI?  Just because it makes the eggheads job a little easier.  But now we have computers and they don&#8217;t complain nearly as much as eggheads, so there&#8217;s no real reason to do this anymore, we&#8217;ll let the computer do it for us.<\/p>\n<p>In the example code above I wrote:<\/p>\n<div class=\"codecolorer-container actionscript default\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><div class=\"actionscript codecolorer\"><span class=\"co1\">\/\/<\/span><br \/>\n<span class=\"kw2\">var<\/span> xSteps = magicTrigFunctionX<span class=\"br0\">&#40;<\/span>pointRatio<span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"kw2\">var<\/span> ySteps = magicTrigFunctionY<span class=\"br0\">&#40;<\/span>pointRatio<span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"co1\">\/\/<\/span><\/div><\/div>\n<p>But the eggheads want to see:<\/p>\n<div class=\"codecolorer-container actionscript default\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><div class=\"actionscript codecolorer\"><span class=\"co1\">\/\/<\/span><br \/>\n<span class=\"kw2\">var<\/span> xSteps = <span class=\"kw3\">Math<\/span>.<span class=\"kw3\">cos<\/span><span class=\"br0\">&#40;<\/span>pointRatio<span class=\"sy0\">*<\/span><span class=\"nu0\">2<\/span><span class=\"sy0\">*<\/span><span class=\"kw3\">Math<\/span>.<span class=\"kw3\">PI<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"kw2\">var<\/span> ySteps = <span class=\"kw3\">Math<\/span>.<span class=\"kw3\">sin<\/span><span class=\"br0\">&#40;<\/span>pointRatio<span class=\"sy0\">*<\/span><span class=\"nu0\">2<\/span><span class=\"sy0\">*<\/span><span class=\"kw3\">Math<\/span>.<span class=\"kw3\">PI<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"co1\">\/\/<\/span><\/div><\/div>\n<p>If you want to be a conformist you can use the code above and all will be fine.  You&#8217;ll be using Flash&#8217;s native functions and the eggheads won&#8217;t laugh at you for using &#8220;magic&#8221; functions.  If you&#8217;d like to make things a little easier, you might consider making some custom functions like this:<\/p>\n<div class=\"codecolorer-container actionscript default\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><div class=\"actionscript codecolorer\"><span class=\"co1\">\/\/<\/span><br \/>\n<span class=\"kw2\">function<\/span> magicTrigFunctionX <span class=\"br0\">&#40;<\/span>pointRatio<span class=\"br0\">&#41;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">return<\/span> <span class=\"kw3\">Math<\/span>.<span class=\"kw3\">cos<\/span><span class=\"br0\">&#40;<\/span>pointRatio<span class=\"sy0\">*<\/span><span class=\"nu0\">2<\/span><span class=\"sy0\">*<\/span><span class=\"kw3\">Math<\/span>.<span class=\"kw3\">PI<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"br0\">&#125;<\/span><br \/>\n<span class=\"kw2\">function<\/span> magicTrigFunctionY <span class=\"br0\">&#40;<\/span>pointRatio<span class=\"br0\">&#41;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">return<\/span> <span class=\"kw3\">Math<\/span>.<span class=\"kw3\">sin<\/span><span class=\"br0\">&#40;<\/span>pointRatio<span class=\"sy0\">*<\/span><span class=\"nu0\">2<\/span><span class=\"sy0\">*<\/span><span class=\"kw3\">Math<\/span>.<span class=\"kw3\">PI<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"br0\">&#125;<\/span><br \/>\n<span class=\"co1\">\/\/<\/span><\/div><\/div>\n<p>Adding the above functions to our previous code and removing all the comments gives us the following:<\/p>\n<div class=\"codecolorer-container actionscript default\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><div class=\"actionscript codecolorer\"><span class=\"co1\">\/\/<\/span><br \/>\n<span class=\"kw2\">function<\/span> magicTrigFunctionX <span class=\"br0\">&#40;<\/span>pointRatio<span class=\"br0\">&#41;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">return<\/span> <span class=\"kw3\">Math<\/span>.<span class=\"kw3\">cos<\/span><span class=\"br0\">&#40;<\/span>pointRatio<span class=\"sy0\">*<\/span><span class=\"nu0\">2<\/span><span class=\"sy0\">*<\/span><span class=\"kw3\">Math<\/span>.<span class=\"kw3\">PI<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"br0\">&#125;<\/span><br \/>\n<span class=\"kw2\">function<\/span> magicTrigFunctionY <span class=\"br0\">&#40;<\/span>pointRatio<span class=\"br0\">&#41;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">return<\/span> <span class=\"kw3\">Math<\/span>.<span class=\"kw3\">sin<\/span><span class=\"br0\">&#40;<\/span>pointRatio<span class=\"sy0\">*<\/span><span class=\"nu0\">2<\/span><span class=\"sy0\">*<\/span><span class=\"kw3\">Math<\/span>.<span class=\"kw3\">PI<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"br0\">&#125;<\/span><br \/>\n<span class=\"co1\">\/\/<\/span><br \/>\n<span class=\"kw2\">function<\/span> drawCircle<span class=\"br0\">&#40;<\/span>centerX, centerY, radius, sides<span class=\"br0\">&#41;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">for<\/span><span class=\"br0\">&#40;<\/span><span class=\"kw2\">var<\/span> i=<span class=\"nu0\">0<\/span>; i<span class=\"sy0\">&lt;<\/span>=sides; i++<span class=\"br0\">&#41;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw2\">var<\/span> pointRatio = i<span class=\"sy0\">\/<\/span>sides;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw2\">var<\/span> xSteps = magicTrigFunctionX<span class=\"br0\">&#40;<\/span>pointRatio<span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw2\">var<\/span> ySteps = magicTrigFunctionY<span class=\"br0\">&#40;<\/span>pointRatio<span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw2\">var<\/span> pointX = centerX + xSteps <span class=\"sy0\">*<\/span> radius;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw2\">var<\/span> pointY = centerY + ySteps <span class=\"sy0\">*<\/span> radius;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw3\">this<\/span>.<span class=\"kw3\">lineTo<\/span><span class=\"br0\">&#40;<\/span>pointX, pointY<span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><br \/>\n<span class=\"co1\">\/\/<\/span><br \/>\n<span class=\"kw3\">lineStyle<\/span><span class=\"br0\">&#40;<\/span><span class=\"nu0\">0<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"co1\">\/\/<\/span><br \/>\ndrawCircle<span class=\"br0\">&#40;<\/span><span class=\"nu0\">250<\/span>, <span class=\"nu0\">250<\/span>, <span class=\"nu0\">200<\/span>, <span class=\"nu0\">100<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"co1\">\/\/<\/span><\/div><\/div>\n<p>Which produces the following SWF file:<\/p>\n\n<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"\n\t\t\tid=\"fm_drawcircle_01_817287610\"\n\t\t\tclass=\"flashmovie\"\n\t\t\twidth=\"500\"\n\t\t\theight=\"500\">\n\t<param name=\"movie\" value=\"\/blog\/wp-content\/uploads\/2007\/06\/drawcircle_01.swf\" \/>\n\t<!--[if !IE]>-->\n\t<object\ttype=\"application\/x-shockwave-flash\"\n\t\t\tdata=\"\/blog\/wp-content\/uploads\/2007\/06\/drawcircle_01.swf\"\n\t\t\tname=\"fm_drawcircle_01_817287610\"\n\t\t\twidth=\"500\"\n\t\t\theight=\"500\">\n\t<!--<![endif]-->\n\t\t\n\t<!--[if !IE]>-->\n\t<\/object>\n\t<!--<![endif]-->\n<\/object>\n<p>As you can see, there is a slight flaw with the code in that it starts drawing our circle from the default position of (0, 0) then draws a line all the way over to our first point on the circle.  To fix this we need to modify the code to start off by moving the pen to the first point on the circle and then drawing the lines to all of the other points.<\/p>\n<div class=\"codecolorer-container actionscript default\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><div class=\"actionscript codecolorer\"><span class=\"co1\">\/\/<\/span><br \/>\n<span class=\"kw2\">function<\/span> magicTrigFunctionX <span class=\"br0\">&#40;<\/span>pointRatio<span class=\"br0\">&#41;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">return<\/span> <span class=\"kw3\">Math<\/span>.<span class=\"kw3\">cos<\/span><span class=\"br0\">&#40;<\/span>pointRatio<span class=\"sy0\">*<\/span><span class=\"nu0\">2<\/span><span class=\"sy0\">*<\/span><span class=\"kw3\">Math<\/span>.<span class=\"kw3\">PI<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"br0\">&#125;<\/span><br \/>\n<span class=\"kw2\">function<\/span> magicTrigFunctionY <span class=\"br0\">&#40;<\/span>pointRatio<span class=\"br0\">&#41;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">return<\/span> <span class=\"kw3\">Math<\/span>.<span class=\"kw3\">sin<\/span><span class=\"br0\">&#40;<\/span>pointRatio<span class=\"sy0\">*<\/span><span class=\"nu0\">2<\/span><span class=\"sy0\">*<\/span><span class=\"kw3\">Math<\/span>.<span class=\"kw3\">PI<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"br0\">&#125;<\/span><br \/>\n<span class=\"co1\">\/\/<\/span><br \/>\n<span class=\"kw2\">function<\/span> drawCircle<span class=\"br0\">&#40;<\/span>centerX, centerY, radius, sides<span class=\"br0\">&#41;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/<\/span><br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/ Move the pen to the first point on the circle.<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw3\">this<\/span>.<span class=\"kw3\">moveTo<\/span><span class=\"br0\">&#40;<\/span>centerX + radius, &nbsp;centerY<span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">for<\/span><span class=\"br0\">&#40;<\/span><span class=\"kw2\">var<\/span> i=<span class=\"nu0\">0<\/span>; i<span class=\"sy0\">&lt;<\/span>=sides; i++<span class=\"br0\">&#41;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw2\">var<\/span> pointRatio = i<span class=\"sy0\">\/<\/span>sides;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw2\">var<\/span> xSteps = magicTrigFunctionX<span class=\"br0\">&#40;<\/span>pointRatio<span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw2\">var<\/span> ySteps = magicTrigFunctionY<span class=\"br0\">&#40;<\/span>pointRatio<span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw2\">var<\/span> pointX = centerX + xSteps <span class=\"sy0\">*<\/span> radius;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw2\">var<\/span> pointY = centerY + ySteps <span class=\"sy0\">*<\/span> radius;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw3\">this<\/span>.<span class=\"kw3\">lineTo<\/span><span class=\"br0\">&#40;<\/span>pointX, pointY<span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><br \/>\n<span class=\"co1\">\/\/<\/span><br \/>\n<span class=\"kw3\">lineStyle<\/span><span class=\"br0\">&#40;<\/span><span class=\"nu0\">0<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"co1\">\/\/<\/span><br \/>\ndrawCircle<span class=\"br0\">&#40;<\/span><span class=\"nu0\">250<\/span>, <span class=\"nu0\">250<\/span>, <span class=\"nu0\">200<\/span>, <span class=\"nu0\">100<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"co1\">\/\/<\/span><\/div><\/div>\n<p>Running the above code produces the following SWF file:<\/p>\n\n<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"\n\t\t\tid=\"fm_drawcircle_02_1132156505\"\n\t\t\tclass=\"flashmovie\"\n\t\t\twidth=\"500\"\n\t\t\theight=\"500\">\n\t<param name=\"movie\" value=\"\/blog\/wp-content\/uploads\/2007\/06\/drawcircle_02.swf\" \/>\n\t<!--[if !IE]>-->\n\t<object\ttype=\"application\/x-shockwave-flash\"\n\t\t\tdata=\"\/blog\/wp-content\/uploads\/2007\/06\/drawcircle_02.swf\"\n\t\t\tname=\"fm_drawcircle_02_1132156505\"\n\t\t\twidth=\"500\"\n\t\t\theight=\"500\">\n\t<!--<![endif]-->\n\t\t\n\t<!--[if !IE]>-->\n\t<\/object>\n\t<!--<![endif]-->\n<\/object>\n<p>So there you have it.  One circle drawn with ActionScript.  And all you had to do was count from 0 to 1 (sort of)  \ud83d\ude09 .<\/p>\n<p><strong>Update<\/strong>: The next tutorial in this series is <a title=\"Tutorial explaining How to Draw an Arc\" href=\"https:\/\/www.pixelwit.com\/blog\/2007\/07\/draw-an-arc-with-actionscript\/\">How to Draw an Arc with ActionScript<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tutorial examining the ActionScript code and concepts needed to plot a series of points around the circumference of a circle. Includes a brief introduction to the concepts of trigonometry.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[8],"tags":[23,45,36,37],"class_list":["post-86","post","type-post","status-publish","format-standard","hentry","category-flash","tag-actionscript","tag-draw","tag-swfs","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/posts\/86","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/comments?post=86"}],"version-history":[{"count":0,"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/posts\/86\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/media?parent=86"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/categories?post=86"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/tags?post=86"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}