<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flassari.is &#187; mask</title>
	<atom:link href="http://flassari.is/tag/mask/feed/" rel="self" type="application/rss+xml" />
	<link>http://flassari.is</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Mon, 19 Jul 2010 16:09:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Pie mask in AS3</title>
		<link>http://flassari.is/2009/11/pie-mask-in-as3/</link>
		<comments>http://flassari.is/2009/11/pie-mask-in-as3/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 17:02:17 +0000</pubDate>
		<dc:creator>Flassari</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[mask]]></category>
		<category><![CDATA[percentage]]></category>
		<category><![CDATA[pie]]></category>
		<category><![CDATA[progress]]></category>
		<category><![CDATA[timer]]></category>

		<guid isPermaLink="false">http://flassari.is/?p=240</guid>
		<description><![CDATA[Sometimes I have the need for a rotational progress bar that acts like a pie growing bigger (or smaller if that strikes your fancy). As usual, I made my own =) [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes I have the need for a rotational progress bar that acts like a pie growing bigger (or smaller if that strikes your fancy). As usual, I made my own =)<br />
The function drawPieMask takes first the <strong>graphics</strong> object of the displayObject instance and draws a part of pie on it, <strong>percentage</strong> set&#8217;s how big the part is.<br />
If you want to offset the rotation of the pie (it starts to the right by default) you can set the <strong>rotation</strong> parameter. Note that rotation is in radians, not degrees, but you can multiply your degrees by (Math.PI/180) to convert to radians.<br />
Lastly, the <strong>sides</strong> property determines how many sides the circle drawn in the mask has. You can see an example of different pie masks after the code.</p>
<p>To make the code as customizable as possible, it does not make a call to beginFill in case you want to set your own fill (or gradientfill even?).<br />
If you just want to use it as a basic mask, just call beginFill(0) before and endFill() after the call to drawPieMask.</p>
<pre class="brush: as3">function drawPieMask(graphics:Graphics, percentage:Number, radius:Number = 50, x:Number = 0, y:Number = 0, rotation:Number = 0, sides:int = 6):void {
	// graphics should have its beginFill function already called by now
	graphics.moveTo(x, y);
	if (sides < 3) sides = 3; // 3 sides minimum
	// Increase the length of the radius to cover the whole target
	radius /= Math.cos(1/sides * Math.PI);
	// Shortcut function
	var lineToRadians:Function = function(rads:Number):void {
		graphics.lineTo(Math.cos(rads) * radius + x, Math.sin(rads) * radius + y);
	};
	// Find how many sides we have to draw
	var sidesToDraw:int = Math.floor(percentage * sides);
	for (var i:int = 0; i <= sidesToDraw; i++)
		lineToRadians((i / sides) * (Math.PI * 2) + rotation);
	// Draw the last fractioned side
	if (percentage * sides != sidesToDraw)
		lineToRadians(percentage * (Math.PI * 2) + rotation);
}</pre>
<p>Example of different sides values. The last circle has a pie with 3 sides as a mask.<br />
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="450" height="310"><param name="movie" value="/wp-content/uploads/2009/11/PieMaskExample.swf" /><!--[if !IE]>--><object type="application/x-shockwave-flash" data="/wp-content/uploads/2009/11/PieMaskExample.swf" width="450" height="310"><!--<![endif]-->
<div>
<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>
<p><!--[if !IE]>--></object><!--<![endif]--></object></p>
<p>You can get the <a href='http://flassari.is/wp-content/uploads/2009/11/PieMaskExample.zip'>example fla here.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://flassari.is/2009/11/pie-mask-in-as3/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
