{"id":748,"date":"2008-12-02T08:00:06","date_gmt":"2008-12-02T13:00:06","guid":{"rendered":"http:\/\/www.pixelwit.com\/blog\/?p=748"},"modified":"2009-08-15T19:55:37","modified_gmt":"2009-08-16T00:55:37","slug":"drawing-closed-arc-shape","status":"publish","type":"post","link":"https:\/\/www.pixelwit.com\/blog\/2008\/12\/02\/drawing-closed-arc-shape\/","title":{"rendered":"Drawing a Closed Arc Shape"},"content":{"rendered":"<p>This tutorial provides the ActionScript needed to draw a &#8220;Closed Arc&#8221; which is my way of describing the solid shape created by connecting a pair of concentric arcs with 2 straight lines.  Here&#8217;s an illustration to explain:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"Regular Arc Compared to a Solid Arc\" src=\"https:\/\/www.pixelwit.com\/blog\/wp-content\/uploads\/2008\/12\/regular-vs-solid-arc.png\" alt=\"\" title=\"regular-vs-solid-arc.jpg\" width=\"444\" height=\"184\" class=\"alignnone size-full wp-image-758\" \/><\/p>\n<p>(If you&#8217;re new to drawing arcs I suggest reading my previous <a title=\"How to Draw a Circle with ActionScript\" href=\"https:\/\/www.pixelwit.com\/blog\/2007\/06\/basic-circle-drawing-actionscript\/\">circle<\/a> and <a title=\"How to Draw an Arc with ActionScript\" href=\"https:\/\/www.pixelwit.com\/blog\/2007\/07\/draw-an-arc-with-actionscript\/\">arc<\/a> tutorials for an introduction to trigonometry in Flash.)<\/p>\n<p>In my <a title=\"Draw an Arc with ActionScript\" href=\"https:\/\/www.pixelwit.com\/blog\/2007\/07\/draw-an-arc-with-actionscript\/\">standard arc drawing tutorial<\/a> I explained the following ActionScript code<!--more-->:<\/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> drawArc<span class=\"br0\">&#40;<\/span>centerX, centerY, radius, startAngle, arcAngle, steps<span class=\"br0\">&#41;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw2\">var<\/span> twoPI = <span class=\"nu0\">2<\/span> <span class=\"sy0\">*<\/span> <span class=\"kw3\">Math<\/span>.<span class=\"kw3\">PI<\/span>;<br \/>\n&nbsp; &nbsp; <span class=\"kw2\">var<\/span> angleStep = arcAngle<span class=\"sy0\">\/<\/span>steps;<br \/>\n&nbsp; &nbsp; <span class=\"kw2\">var<\/span> xx = centerX + <span class=\"kw3\">Math<\/span>.<span class=\"kw3\">cos<\/span><span class=\"br0\">&#40;<\/span>startAngle <span class=\"sy0\">*<\/span> twoPI<span class=\"br0\">&#41;<\/span> <span class=\"sy0\">*<\/span> radius;<br \/>\n&nbsp; &nbsp; <span class=\"kw2\">var<\/span> yy = centerY + <span class=\"kw3\">Math<\/span>.<span class=\"kw3\">sin<\/span><span class=\"br0\">&#40;<\/span>startAngle <span class=\"sy0\">*<\/span> twoPI<span class=\"br0\">&#41;<\/span> <span class=\"sy0\">*<\/span> radius;<br \/>\n&nbsp; &nbsp; <span class=\"kw3\">moveTo<\/span><span class=\"br0\">&#40;<\/span>xx, yy<span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; <span class=\"kw1\">for<\/span><span class=\"br0\">&#40;<\/span><span class=\"kw2\">var<\/span> i=<span class=\"nu0\">1<\/span>; i<span class=\"sy0\">&lt;<\/span>=steps; i++<span class=\"br0\">&#41;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw2\">var<\/span> angle = startAngle + i <span class=\"sy0\">*<\/span> angleStep;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; xx = centerX + <span class=\"kw3\">Math<\/span>.<span class=\"kw3\">cos<\/span><span class=\"br0\">&#40;<\/span>angle <span class=\"sy0\">*<\/span> twoPI<span class=\"br0\">&#41;<\/span> <span class=\"sy0\">*<\/span> radius;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; yy = centerY + <span class=\"kw3\">Math<\/span>.<span class=\"kw3\">sin<\/span><span class=\"br0\">&#40;<\/span>angle <span class=\"sy0\">*<\/span> twoPI<span class=\"br0\">&#41;<\/span> <span class=\"sy0\">*<\/span> radius;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw3\">lineTo<\/span><span class=\"br0\">&#40;<\/span>xx, yy<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=\"kw3\">lineStyle<\/span><span class=\"br0\">&#40;<\/span><span class=\"nu0\">0<\/span>, 0xFF0000<span class=\"br0\">&#41;<\/span>;<br \/>\ndrawArc<span class=\"br0\">&#40;<\/span><span class=\"nu0\">250<\/span>, <span class=\"nu0\">250<\/span>, <span class=\"nu0\">200<\/span>, <span class=\"nu0\">45<\/span><span class=\"sy0\">\/<\/span><span class=\"nu0\">360<\/span>, -<span class=\"nu0\">90<\/span><span class=\"sy0\">\/<\/span><span class=\"nu0\">360<\/span>, <span class=\"nu0\">20<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"co1\">\/\/<\/span><\/div><\/div>\n<p>The above code produced this SWF file:<\/p>\n\n<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"\n\t\t\tid=\"fm_drawarc_01_709259242\"\n\t\t\tclass=\"flashmovie\"\n\t\t\twidth=\"500\"\n\t\t\theight=\"500\">\n\t<param name=\"movie\" value=\"https:\/\/www.pixelwit.com\/blog\/wp-content\/uploads\/2007\/07\/drawarc_01.swf\" \/>\n\t<!--[if !IE]>-->\n\t<object\ttype=\"application\/x-shockwave-flash\"\n\t\t\tdata=\"https:\/\/www.pixelwit.com\/blog\/wp-content\/uploads\/2007\/07\/drawarc_01.swf\"\n\t\t\tname=\"fm_drawarc_01_709259242\"\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>It doesn't look like much.  But by looking at the above SWF you can probably deduce all of the steps needed to draw a solid arc:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.pixelwit.com\/blog\/wp-content\/uploads\/2008\/12\/solid-arc-steps.png\" alt=\"\" title=\"solid-arc-steps.png\" width=\"224\" height=\"184\" class=\"alignnone size-full wp-image-762\" \/><\/p>\n<ol>\n<li>Draw the inner part of the arc in one direction.<\/li>\n<li>Draw a straight line to the outer part of the arc.<\/li>\n<li>Draw the outer part of the arc in the opposite direction.<\/li>\n<li>Draw a straight line back to the inner part of the arc to complete the shape.<\/li>\n<\/ol>\n<p>Here you can see how the above ActionScript has been modified to do just that:<\/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\">\/\/ The DrawSolidArc function takes standard arc drawing<\/span><br \/>\n<span class=\"co1\">\/\/ arguments but the &quot;radius&quot; has been split into 2 different<\/span><br \/>\n<span class=\"co1\">\/\/ variables, &quot;innerRadius&quot; and &quot;outerRadius&quot;.<\/span><br \/>\n<span class=\"kw2\">function<\/span> DrawSolidArc <span class=\"br0\">&#40;<\/span>centerX, centerY, innerRadius, outerRadius, startAngle, arcAngle, steps<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\">\/\/ Used to convert angles to radians.<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw2\">var<\/span> twoPI = <span class=\"nu0\">2<\/span> <span class=\"sy0\">*<\/span> <span class=\"kw3\">Math<\/span>.<span class=\"kw3\">PI<\/span>;<br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/<\/span><br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/ How much to rotate for each point along the arc.<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw2\">var<\/span> angleStep = arcAngle<span class=\"sy0\">\/<\/span>steps;<br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/<\/span><br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/ Variables set later.<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw2\">var<\/span> angle, i, endAngle;<br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/<\/span><br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/ Find the coordinates of the first point on the inner arc.<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw2\">var<\/span> xx = centerX + <span class=\"kw3\">Math<\/span>.<span class=\"kw3\">cos<\/span><span class=\"br0\">&#40;<\/span>startAngle <span class=\"sy0\">*<\/span> twoPI<span class=\"br0\">&#41;<\/span> <span class=\"sy0\">*<\/span> innerRadius;<br \/>\n&nbsp; &nbsp; <span class=\"kw2\">var<\/span> yy = centerY + <span class=\"kw3\">Math<\/span>.<span class=\"kw3\">sin<\/span><span class=\"br0\">&#40;<\/span>startAngle <span class=\"sy0\">*<\/span> twoPI<span class=\"br0\">&#41;<\/span> <span class=\"sy0\">*<\/span> innerRadius;<br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/<\/span><br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/ Store the coordiantes in an object.<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw2\">var<\/span> startPoint = <span class=\"br0\">&#123;<\/span>x:xx, y:yy<span class=\"br0\">&#125;<\/span>;<br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/<\/span><br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/ Move to the first point on the inner arc.<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw3\">moveTo<\/span><span class=\"br0\">&#40;<\/span>xx, yy<span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/<\/span><br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/ Draw all of the other points along the inner arc.<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">for<\/span><span class=\"br0\">&#40;<\/span>i=<span class=\"nu0\">1<\/span>; i<span class=\"sy0\">&lt;<\/span>=steps; i++<span class=\"br0\">&#41;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; angle = <span class=\"br0\">&#40;<\/span>startAngle + i <span class=\"sy0\">*<\/span> angleStep<span class=\"br0\">&#41;<\/span> <span class=\"sy0\">*<\/span> twoPI;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; xx = centerX + <span class=\"kw3\">Math<\/span>.<span class=\"kw3\">cos<\/span><span class=\"br0\">&#40;<\/span>angle<span class=\"br0\">&#41;<\/span> <span class=\"sy0\">*<\/span> innerRadius;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; yy = centerY + <span class=\"kw3\">Math<\/span>.<span class=\"kw3\">sin<\/span><span class=\"br0\">&#40;<\/span>angle<span class=\"br0\">&#41;<\/span> <span class=\"sy0\">*<\/span> innerRadius;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw3\">lineTo<\/span><span class=\"br0\">&#40;<\/span>xx, yy<span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/<\/span><br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/ Determine the ending angle of the arc so you can<\/span><br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/ rotate around the outer arc in the opposite direction.<\/span><br \/>\n&nbsp; &nbsp; endAngle = startAngle + arcAngle;<br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/<\/span><br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/ Start drawing all points on the outer arc.<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">for<\/span><span class=\"br0\">&#40;<\/span>i=<span class=\"nu0\">0<\/span>; i<span class=\"sy0\">&lt;<\/span>=steps; 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\">\/\/ To go the opposite direction, we subtract rather than add.<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; angle = <span class=\"br0\">&#40;<\/span>endAngle - i <span class=\"sy0\">*<\/span> angleStep<span class=\"br0\">&#41;<\/span> <span class=\"sy0\">*<\/span> twoPI;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; xx = centerX + <span class=\"kw3\">Math<\/span>.<span class=\"kw3\">cos<\/span><span class=\"br0\">&#40;<\/span>angle<span class=\"br0\">&#41;<\/span> <span class=\"sy0\">*<\/span> outerRadius;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; yy = centerY + <span class=\"kw3\">Math<\/span>.<span class=\"kw3\">sin<\/span><span class=\"br0\">&#40;<\/span>angle<span class=\"br0\">&#41;<\/span> <span class=\"sy0\">*<\/span> outerRadius;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw3\">lineTo<\/span><span class=\"br0\">&#40;<\/span>xx, yy<span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/<\/span><br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/ Close the shape by drawing a straight<\/span><br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/ line back to the inner arc.<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw3\">lineTo<\/span><span class=\"br0\">&#40;<\/span>startPoint.<span class=\"me1\">x<\/span>, startPoint.<span class=\"me1\">y<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"br0\">&#125;<\/span><br \/>\n<span class=\"co1\">\/\/<\/span><br \/>\n<span class=\"co1\">\/\/ Draw 4 colored arcs around a circle without any overlap.<\/span><br \/>\n<span class=\"kw3\">beginFill<\/span><span class=\"br0\">&#40;<\/span>0xFF0000, <span class=\"nu0\">50<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\nDrawSolidArc <span class=\"br0\">&#40;<\/span><span class=\"nu0\">250<\/span>, <span class=\"nu0\">250<\/span>, <span class=\"nu0\">80<\/span>, <span class=\"nu0\">200<\/span>, <span class=\"nu0\">45<\/span><span class=\"sy0\">\/<\/span><span class=\"nu0\">360<\/span>, -<span class=\"nu0\">90<\/span><span class=\"sy0\">\/<\/span><span class=\"nu0\">360<\/span>, <span class=\"nu0\">20<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"kw3\">beginFill<\/span><span class=\"br0\">&#40;<\/span>0x00FF00, <span class=\"nu0\">50<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\nDrawSolidArc <span class=\"br0\">&#40;<\/span><span class=\"nu0\">250<\/span>, <span class=\"nu0\">250<\/span>, <span class=\"nu0\">80<\/span>, <span class=\"nu0\">200<\/span>, <span class=\"nu0\">135<\/span><span class=\"sy0\">\/<\/span><span class=\"nu0\">360<\/span>, -<span class=\"nu0\">90<\/span><span class=\"sy0\">\/<\/span><span class=\"nu0\">360<\/span>, <span class=\"nu0\">20<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"kw3\">beginFill<\/span><span class=\"br0\">&#40;<\/span>0x0000FF, <span class=\"nu0\">50<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\nDrawSolidArc <span class=\"br0\">&#40;<\/span><span class=\"nu0\">250<\/span>, <span class=\"nu0\">250<\/span>, <span class=\"nu0\">80<\/span>, <span class=\"nu0\">200<\/span>, <span class=\"nu0\">225<\/span><span class=\"sy0\">\/<\/span><span class=\"nu0\">360<\/span>, -<span class=\"nu0\">90<\/span><span class=\"sy0\">\/<\/span><span class=\"nu0\">360<\/span>, <span class=\"nu0\">20<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"kw3\">beginFill<\/span><span class=\"br0\">&#40;<\/span>0xFFFF00, <span class=\"nu0\">50<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\nDrawSolidArc <span class=\"br0\">&#40;<\/span><span class=\"nu0\">250<\/span>, <span class=\"nu0\">250<\/span>, <span class=\"nu0\">80<\/span>, <span class=\"nu0\">200<\/span>, <span class=\"nu0\">315<\/span><span class=\"sy0\">\/<\/span><span class=\"nu0\">360<\/span>, -<span class=\"nu0\">90<\/span><span class=\"sy0\">\/<\/span><span class=\"nu0\">360<\/span>, <span class=\"nu0\">20<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"co1\">\/\/<\/span><br \/>\n<span class=\"co1\">\/\/<\/span><\/div><\/div>\n<p>The preceding ActionScript code produces a series of closed arcs forming a circle.  The arcs are drawn with 50% opacity to show that they fit together tightly and without any overlap.<\/p>\n\n<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"\n\t\t\tid=\"fm_draw-solid-arc_159168618\"\n\t\t\tclass=\"flashmovie\"\n\t\t\twidth=\"500\"\n\t\t\theight=\"500\">\n\t<param name=\"movie\" value=\"https:\/\/www.pixelwit.com\/blog\/wp-content\/uploads\/2008\/12\/draw-solid-arc.swf\" \/>\n\t<!--[if !IE]>-->\n\t<object\ttype=\"application\/x-shockwave-flash\"\n\t\t\tdata=\"https:\/\/www.pixelwit.com\/blog\/wp-content\/uploads\/2008\/12\/draw-solid-arc.swf\"\n\t\t\tname=\"fm_draw-solid-arc_159168618\"\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","protected":false},"excerpt":{"rendered":"<p>This Flash tutorial provides the ActionScript needed to draw a Closed Arc (the solid shape created by connecting a pair of concentric arcs with 2 straight lines).<\/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-748","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\/748","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=748"}],"version-history":[{"count":0,"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/posts\/748\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/media?parent=748"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/categories?post=748"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/tags?post=748"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}