<?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>benwatts.ca &#187; Flash</title>
	<atom:link href="http://benwatts.ca/tag/flash/feed/" rel="self" type="application/rss+xml" />
	<link>http://benwatts.ca</link>
	<description>Designer and Frontend Developer in Ottawa, Canada</description>
	<lastBuildDate>Fri, 22 Jul 2011 19:00:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Sunflowers, Spirals, Flash</title>
		<link>http://benwatts.ca/2009/sunflowers-spirals-flash/</link>
		<comments>http://benwatts.ca/2009/sunflowers-spirals-flash/#comments</comments>
		<pubDate>Sun, 28 Jun 2009 13:44:01 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[experiment]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[generator]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[sunflower]]></category>

		<guid isPermaLink="false">http://www.benwatts.ca/?p=472</guid>
		<description><![CDATA[Recently a project came up that had the potential to use an abstract sunflower as a lovely motif. After looking into it a bit, there happened to be an equation describing the arrangement of seeds in a sunflower. The equations looked fairly straightforward, but I&#8217;m no math wizard and had no idea to figure out [...]]]></description>
			<content:encoded><![CDATA[<p>Recently a project came up that had the potential to use an abstract sunflower as a lovely motif. After looking into it a bit, there happened to be an <a href="http://en.wikipedia.org/wiki/Sunflower#Mathematical_model_of_floret_arrangement">equation describing the arrangement of seeds in a sunflower</a>. The equations looked fairly straightforward, but I&#8217;m no math wizard and had no idea to figure out the x and y coordinates of the &#8216;seeds&#8217;, but lucky for me I happen to sit across from <a title="Rob Villeneuve" href="http://deletedtheory.com/blog/">someone</a> who knows what the hell they&#8217;re doing and as a result I have a simple sunflower generator:</p>
<div id="sunflower-placeholder">To view this content, JavaScript must be enabled, and you need the latest version of the <a href="http://get.adobe.com/flashplayer/">Adobe Flash Player</a>.</div>
<p><script type="text/javascript">
                    // <![CDATA[
                    var flashvars = {};
                    var params = {}
                    var attributes = {};
                    swfobject.embedSWF("/wp-content/uploads/2009/06/Sunflower.swf", "sunflower-placeholder", "560", "460", "9.0.0", false, flashvars, params, attributes);
                    //]]&gt;
</script> </p>
<p><span id="more-472"></span></p>
<h3>The Code</h3>
<p>You will need to have a Slider component in your library for this to compile (or remove all references to the slider until it compiles). If you&#8217;re into this type of thing then definitely play around with the constant scaling factor, max number of seeds, and the golden ratio number in the angle (137.5).</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #3f5fbf;">/** <br />
&nbsp;* Sunflower Generator <br />
&nbsp;* June 28, 2009 <br />
&nbsp;*<br />
&nbsp;* @author&nbsp; &nbsp; &nbsp; Ben Watts<br />
&nbsp;* @url &nbsp; &nbsp; &nbsp; &nbsp; http://www.benwatts.ca/<br />
&nbsp;* @post&nbsp; &nbsp; &nbsp; &nbsp; http://www.benwatts.ca/2009/06/28/sunflowers-spirals-flash/<br />
&nbsp;**/</span><br />
<br />
<span style="color: #9900cc; font-weight: bold;">package</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.*;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> fl<span style="color: #000066; font-weight: bold;">.</span>controls<span style="color: #000066; font-weight: bold;">.</span>Slider<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> fl<span style="color: #000066; font-weight: bold;">.</span>events<span style="color: #000066; font-weight: bold;">.</span>SliderEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Sunflower <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">MovieClip</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> maxSeeds<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">9000</span><span style="color: #000066; font-weight: bold;">;</span> &nbsp;<span style="color: #009900; font-style: italic;">// # of seeds</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">c</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">4</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// constant scaling factor (distance btw seeds)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">angle</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Sunflower<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; drawSunflower<span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">.</span>1<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// start with something </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> slider<span style="color: #000066; font-weight: bold;">:</span>Slider = <span style="color: #0033ff; font-weight: bold;">new</span> Slider<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; slider<span style="color: #000066; font-weight: bold;">.</span>liveDragging = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; slider<span style="color: #000066; font-weight: bold;">.</span>minimum = <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; slider<span style="color: #000066; font-weight: bold;">.</span>setSize<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">150</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">5</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; slider<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageWidth</span> <span style="color: #000066; font-weight: bold;">-</span> slider<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; slider<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; slider<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>SliderEvent<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CHANGE</span><span style="color: #000066; font-weight: bold;">,</span> sliderChange<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>slider<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Event handler, whenever the slider's value changes <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param &nbsp; &nbsp; &nbsp; e &nbsp; - SliderEvent<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> sliderChange<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span>SliderEvent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; drawSunflower<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// returns value btw 1.0 and 10.0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Draws the sunflower. <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*&nbsp; @param &nbsp;&nbsp; &nbsp; value &nbsp; - the % of the max number of seeds that are set to be drawn. Expects a float 0 - 1.0<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> drawSunflower<span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> n<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// current seed</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> numSeeds<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = maxSeeds <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// how many seeds should be made</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">try</span> <span style="color: #000000;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">'seed-container'</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">catch</span><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Error</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span> <span style="color: #009966; font-style: italic;">/* this makes me a terrible person, i know. */</span> <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> container<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MovieClip</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">MovieClip</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span> = <span style="color: #990000;">'seed-container'</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>container<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span> n<span style="color: #000066; font-weight: bold;">;</span> n <span style="color: #000066; font-weight: bold;">&lt;</span> numSeeds<span style="color: #000066; font-weight: bold;">;</span> n<span style="color: #000066; font-weight: bold;">++</span> <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> seed<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; seed<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span>0xff0000 <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000;">&#40;</span>n<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">15</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">1.0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// messing with seed colour, don't really know what i'm doing ;)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; seed<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">drawCircle</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; seed<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> r<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">c</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sqrt</span><span style="color: #000000;">&#40;</span>n<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">angle</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = n <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">137.5</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; seed<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = r <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">angle</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; seed<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = r <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">angle</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>seed<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// centre on the stage</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageWidth</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageHeight</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #000000;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://benwatts.ca/2009/sunflowers-spirals-flash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jump Around</title>
		<link>http://benwatts.ca/2009/jump-around/</link>
		<comments>http://benwatts.ca/2009/jump-around/#comments</comments>
		<pubDate>Fri, 01 May 2009 02:01:18 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[jumping]]></category>

		<guid isPermaLink="false">http://www.benwatts.ca/?p=391</guid>
		<description><![CDATA[I&#8217;ve been tinkering with Sprites and the idea of making a silly little game in Flash with AS3, to flex (PUN?) my actionscript chops. This is the meagre progress I&#8217;ve made so far, and I thought I&#8217;d make it open source for all the world to gasp at my horrendous code. I&#8217;m currently at the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been tinkering with Sprites and the idea of making a silly little game in Flash with AS3, to flex (PUN?) my actionscript chops. This is the meagre progress I&#8217;ve made so far, and I thought I&#8217;d make it open source for all the world to gasp at my horrendous code. I&#8217;m currently at the<em> &#8220;HOLY CRAP I MADE A CHARACTER THAT CAN JUMP USING AS3&#8243;</em> stage of development. </p>
<p>How about that linear jump? Needs some gravity love, eh? </p>
<div id="game090430"><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></div>
<p><strong> <a href="/wp-content/storage/mariogame/090430/mario.zip">SOURCE</a> (71 KB, .zip) </strong></p>
<p><small> You might have to click on the swf to give it focus and enable keyboard controls to move/jump. Shift+Left/Right to &#8216;run&#8217; (*his legs don&#8217;t move*). No collision detection whatsoever, yet.</small></p>
<p><script type="text/javascript">
			var flashvars = {};
			var params = {};
			var attributes = {};
			swfobject.embedSWF("/wp-content/storage/mariogame/090430/bin/mario.swf", "game090430", "500", "250", "10.0.0", false, flashvars, params, attributes);
		</script></p>
<p>Below is the event handler I&#8217;m using for jumping, which is called on every frame after the user presses the up key, until the jump is complete:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> jump<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> jumpDestination<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = groundLevel <span style="color: #000066; font-weight: bold;">-</span> MAX_JUMP_HEIGHT<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// only attempt to stop the jump if you've already left the ground</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> inAir <span style="color: #000066; font-weight: bold;">&amp;&amp;</span> <span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #004993;">height</span> == groundLevel <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;dy = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;groundLevel = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;inAir = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span> &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> jump<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">&gt;</span>= jumpDestination <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; inAir = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; dy <span style="color: #000066; font-weight: bold;">-</span>= <span style="color: #000000; font-weight:bold;">4</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">&lt;</span>= jumpDestination <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; dy <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #000000; font-weight:bold;">4</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Eh? Eh? I felt good after figuring that one out. Ahaha. Looking at it though, I think I should be stopping the jump based upon some collision detection. As it stands right now, it wouldn&#8217;t work if you wanted to jump onto something (since it will only stop the jump if you hit the point you&#8217;ve started at. Development is early, what can I say. </p>
]]></content:encoded>
			<wfw:commentRss>http://benwatts.ca/2009/jump-around/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash Flash Everywhere</title>
		<link>http://benwatts.ca/2008/flash-flash-everywhere/</link>
		<comments>http://benwatts.ca/2008/flash-flash-everywhere/#comments</comments>
		<pubDate>Mon, 23 Jun 2008 02:02:34 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[news]]></category>

		<guid isPermaLink="false">http://localhost/benwatts.ca/?p=135</guid>
		<description><![CDATA[I would by no means call myself anything more than a &#8216;novice&#8217; at programming with Actionscript; it&#8217;s not something I have volumes of experience in, outside of the program I took in college. I swore I&#8217;d never work on another Flash project after my last class, and a couple weeks later I was at a [...]]]></description>
			<content:encoded><![CDATA[<p>I would by no means call myself anything more than a &#8216;novice&#8217; at programming with Actionscript; it&#8217;s not something I have volumes of experience in, outside of the program I took in college. I swore I&#8217;d never work on another Flash project after my last class, and a couple weeks later I was at a <a href="/2008/02/25/flexible/">3-day Flex training course</a>.  To continue the trend, I&#8217;ve been doing quite a lot of Actionscript (3) at work for the past month or so at work, making interactive maps (eep!) &#8212; I&#8217;ve been called &#8216;the map guy&#8217; by some because of it.</p>
<p><strong>HENCE ALL THE ACTIONSCRIPT 3 RELATED POSTS.</strong></p>
<p>Indeed, I had set up a separate blog to keep track of the little nuances/annoyances I learned (and that I&#8217;m still learning!) while reading and programming in AS3. Then I realized it was a waste of time to maintain another blog and promptly merged it with this one. Funny how things work out &#8230; </p>
]]></content:encoded>
			<wfw:commentRss>http://benwatts.ca/2008/flash-flash-everywhere/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash Pixelshift Bug</title>
		<link>http://benwatts.ca/2008/flash-pixelshift-bug/</link>
		<comments>http://benwatts.ca/2008/flash-pixelshift-bug/#comments</comments>
		<pubDate>Wed, 16 Apr 2008 13:58:36 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[png]]></category>

		<guid isPermaLink="false">http://www.rainiscold.ca/seaturtle/?p=7</guid>
		<description><![CDATA[Flash apparently has a thing with cutting off .pngs. Putting the graphic element in a movieclip with a bottom right alignment seems to solve the problem, as per here: http://www.fatorcaos.com.br/flashimagebug/]]></description>
			<content:encoded><![CDATA[<p>Flash apparently has a thing with cutting off .pngs. Putting the graphic element in a movieclip with a bottom right alignment seems to solve the problem, as per here:</p>
<p>http://www.fatorcaos.com.br/flashimagebug/</p>
]]></content:encoded>
			<wfw:commentRss>http://benwatts.ca/2008/flash-pixelshift-bug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

