<?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>alecmce.com &#187; christmas</title>
	<atom:link href="http://alecmce.com/tag/christmas/feed" rel="self" type="application/rss+xml" />
	<link>http://alecmce.com</link>
	<description></description>
	<lastBuildDate>Fri, 18 May 2012 02:54:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Further Festive Flakes</title>
		<link>http://alecmce.com/animation/further-festive-flakes</link>
		<comments>http://alecmce.com/animation/further-festive-flakes#comments</comments>
		<pubDate>Tue, 24 Nov 2009 16:16:01 +0000</pubDate>
		<dc:creator>alecmce</dc:creator>
				<category><![CDATA[animation]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[christmas]]></category>
		<category><![CDATA[snow]]></category>
		<category><![CDATA[snowflake]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=522</guid>
		<description><![CDATA[Some more programmatic snow: roll-over to activate This one is more simple, though the logic is exploded over multiple classes. You can get the source files here. I create a bunch of BitmapData objects with semi-transparent circles to represent snowflakes, called FlakeForms. Then, create a bunch of Flake objects which are essentially positions at which [...]]]></description>
			<content:encoded><![CDATA[<p>Some more programmatic snow:</p>
<div style="text-align: center; font-size: small; margin-bottom: 20px;">
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_0" width="550" height="400">
      <param name="movie" value="http://www.alecmce.com.php5-16.dfw1-1.websitetestlink.com/wp-content/uploads/2009/11/TestSnow1.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://www.alecmce.com.php5-16.dfw1-1.websitetestlink.com/wp-content/uploads/2009/11/TestSnow1.swf" width="550" height="400">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br/>roll-over to activate</div>
<p>This one is more simple, though the logic is exploded over multiple classes. You can <a href='http://www.alecmce.com.php5-16.dfw1-1.websitetestlink.com/wp-content/uploads/2009/11/snow1.zip'>get the source files here</a>. I create a bunch of <code>BitmapData</code> objects with semi-transparent circles to represent snowflakes, called <code>FlakeForms</code>. Then, create a bunch of <code>Flake</code> objects which are essentially positions at which those formal flakes should be drawn. Each <code>EnterFrame</code>, wipe the <code>BitmapData</code> clean, <code>update</code> the flake positions and draw the formal flakes into the updated positions.</p>
<p><span id="more-522"></span></p>
<h3>FlakeForm</h3>
<pre class="brush: as3; title: ; notranslate">
/**
 * Copyright (c) 2009 Alec McEachran
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the &quot;Software&quot;), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */
package
{
	import flash.display.BitmapData;
	import flash.display.Graphics;
	import flash.display.Shape;

	public class FlakeForm extends BitmapData
	{

		public function FlakeForm(radius:int, alpha:Number)
		{
			var n:int = radius &lt;&lt; 1;
			super(n, n, true, 0);

			var shape:Shape = new Shape();
			var graphics:Graphics = shape.graphics;

			graphics.beginFill(0xFFFFFF, alpha);
			graphics.drawCircle(radius, radius, radius);
			graphics.endFill();

			draw(shape);
		}
	}
}
</pre>
<h3>Flake</h3>
<pre class="brush: as3; title: ; notranslate">
/**
 * Copyright (c) 2009 Alec McEachran
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the &quot;Software&quot;), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */
package
{
	import flash.display.BitmapData;
	import flash.geom.Point;
	import flash.geom.Rectangle;

	public class Flake
	{
		private const ORIGIN:Point = new Point(0, 0);

		private var form:FlakeForm;

		private var bounds:Rectangle;

		private var position:Point;
		private var x:Number;

		private var y:Number;

		private var dx:Number;

		private var dy:Number;

		public function Flake(form:FlakeForm, bounds:Rectangle):void
		{
			this.form = form;
			this.bounds = bounds;
			this.position = new Point();

			x = bounds.left + Math.random() * bounds.width;
			y = bounds.top - 20 + Math.random() * (bounds.height + 20);
			dx = Math.random() * 4.2 - 1.5;
			dy = Math.random() * 2 + 1;
		}

		public function update(bitmapData:BitmapData):void
		{
			x += dx;
			y += dy;

			if (x &gt; bounds.right)
				x = bounds.left + x - bounds.right;
			else if (x &lt; bounds.left)
				x = bounds.right + x - bounds.left;

			if (y &gt; bounds.bottom)
				y = bounds.top - 20;

			position.x = x;
			position.y = y;
			bitmapData.copyPixels(form, form.rect, position, null, ORIGIN, true);
		}
	}
}
</pre>
<h3>Snow</h3>
<pre class="brush: as3; title: ; notranslate">
/**
 * Copyright (c) 2009 Alec McEachran
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the &quot;Software&quot;), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */
package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.events.Event;
	import flash.geom.Rectangle;

	public class Snow extends Bitmap
	{

		private var count:int;

		private var flakes:Array;

		public function Snow(width:int, height:int, maxRadius:int, count:int, differentFlakes:int = 20)
		{
			super(new BitmapData(width, height, true, 0x00FFFFFF));
			this.count = count;

			var bounds:Rectangle = new Rectangle(0, 0, width, height);

			var factory:FlakeFactory = new FlakeFactory();
			var forms:Array = factory.generateForms(1, maxRadius, differentFlakes);
			flakes = factory.generateFlakes(count, bounds, forms);

			play();
		}

		public function play():void
		{
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}

		public function stop():void
		{
			removeEventListener(Event.ENTER_FRAME, onEnterFrame);
		}

		private function onEnterFrame(event:Event):void
		{
			var i:int = count;

			bitmapData.fillRect(bitmapData.rect, 0x00FFFFFF);
			while (i--)
			{
				var flake:Flake = flakes[i];
				flake.update(bitmapData);
			}
		}
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/animation/further-festive-flakes/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Festive Flakes</title>
		<link>http://alecmce.com/as3/festive-flakes</link>
		<comments>http://alecmce.com/as3/festive-flakes#comments</comments>
		<pubDate>Tue, 24 Nov 2009 12:19:18 +0000</pubDate>
		<dc:creator>alecmce</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[christmas]]></category>
		<category><![CDATA[snowflake]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=508</guid>
		<description><![CDATA[It&#8217;s got to that time of the year again: the designer is bugging me to make programmatic snow in a new and interesting way. This was rejected, but is fun: roll-over to activate The code for creating the flake pattern is FlakePattern.as, and can be downloaded here! I&#8217;ve also published the entire source code below [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s got to that time of the year again: the designer is bugging me to make programmatic snow in a new and interesting way. This was rejected, but is fun:</p>
<div style="text-align: center; font-size: small; margin-bottom: 20px;">
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_1" width="550" height="400">
      <param name="movie" value="http://www.alecmce.com.php5-16.dfw1-1.websitetestlink.com/wp-content/uploads/2009/11/TestFlakes11.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://www.alecmce.com.php5-16.dfw1-1.websitetestlink.com/wp-content/uploads/2009/11/TestFlakes11.swf" width="550" height="400">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br/>roll-over to activate</div>
<p>The code for creating the flake pattern is <a href="http://www.alecmce.com.php5-16.dfw1-1.websitetestlink.com/wp-content/uploads/2009/11/FlakePattern1.zip">FlakePattern.as, and can be downloaded here!</a> I&#8217;ve also published the entire source code below the fold, if you&#8217;d prefer to browse.</p>
<p>The mechanism came straight out of the way I used to get KS3 (11-14) students to make snowflakes in Maths class at the end of term, translated into a more computational form. I didn&#8217;t add cut-outs to the mechanism; I would be interested to see the code if anyone extends the idea.</p>
<p><span id="more-508"></span></p>
<pre class="brush: as3; title: ; notranslate">
/**
 * Copyright (c) 2009 Alec McEachran
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the &quot;Software&quot;), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */
package
{
	import flash.geom.Point;

	public class FlakePattern
	{

		private const d60:Number = Math.PI / 3;
		private const COS60:Number = Math.cos(d60);
		private const SIN60:Number = Math.sin(d60);

		private const d120:Number = d60 * 2;
		private const COS120:Number = Math.cos(d120);
		private const SIN120:Number = Math.sin(d120);

		public function generate(points:uint, radius:uint):Array
		{
			var pattern:Array = randomPattern(points, radius);
			return generateFromPattern(pattern);
		}

		public function randomPattern(points:uint, radius:uint):Array
		{
			var pattern:Array = [];

			var angle:Number = Math.PI / (points &lt;&lt; 1);
			while (--points &gt; -1)
			{
				var len:int = Math.random() * radius;
				var ang:Number = angle * points;
				pattern[points] = new Point(Math.cos(ang) * len, Math.sin(ang) * len);
			}

			return pattern;
		}

		public function generateFromPattern(points:Array):Array
		{
			var a:Array = convertPointsToSixtyDegrees(points);
			var b:Array = reflectPointsInXAxis(a);
			var c:Array = b.concat(a);
			var c2:Array = rotatePointsAround60Degrees(c);
			var d:Array = c2.concat(c);
			var d2:Array = rotatePointsAround120Degrees(d);
			var e:Array = d2.concat(d);
			var e2:Array = rotatePointsAround120Degrees(e);

			return e2.concat(c2).concat(b).concat(a);
		}

		private function convertPointsToSixtyDegrees(points:Array):Array
		{
			return transformPoints(points, convertPointToSixtyDegrees);
		}

		private function convertPointToSixtyDegrees(point:Point):Point
		{
			return new Point(point.x + point.y * SIN60, point.y * COS60);
		}

		private function reflectPointsInXAxis(points:Array):Array
		{
			var reflected:Array = transformPoints(points, reflectPointInXAxis);
			return reflected.reverse();
		}

		private function reflectPointInXAxis(point:Point):Point
		{
			return new Point(point.x, -point.y);
		}

		private function rotatePointsAround60Degrees(points:Array):Array
		{
			return transformPoints(points, rotatePointAround60Degrees);
		}

		private function rotatePointAround60Degrees(point:Point):Point
		{
			var x:Number = point.x;
			var y:Number = point.y;
			return new Point(x * COS60 + y * SIN60, y * COS60 - x * SIN60);
		}

		private function rotatePointsAround120Degrees(points:Array):Array
		{
			return transformPoints(points, rotatePointAround120Degrees);
		}

		private function rotatePointAround120Degrees(point:Point):Point
		{
			var x:Number = point.x;
			var y:Number = point.y;
			return new Point(x * COS120 + y * SIN120, y * COS120 - x * SIN120);
		}

		private function transformPoints(points:Array, method:Function):Array
		{
			var transformed:Array = [];

			var i:int = points.length;
			while (i--)
			{
				var point:Point = points[i];
				point = method(point);
				transformed[i] = point;
			}

			return transformed;
		}

	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/as3/festive-flakes/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

