In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

何となくふぉーく1::forked from: Triangle in triangle

なんとなくふぉーく1。
/*
	なんとなくふぉーく1。
*/
// forked from cheesepie's Triangle in triangle
package {
	import flash.display.*;
	import flash.events.Event;
	import flash.geom.Point;
	[SWF(backgroundColor="0xffffff", frameRate="30")]
	public class Sketch extends Sprite {
		private var bitmap:Bitmap;
		private var bitmapData:BitmapData;
		// private var cache:BitmapData;
		private var shape:Shape;
		private static const LEVEL_MAX:uint = 6;
		public function Sketch() {
			addEventListener(Event.ADDED_TO_STAGE, _initialize);
		}
		private function _initialize(e:Event):void {
			bitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0xffffff);
			// cache = bitmapData.clone();
			bitmap = addChild(new Bitmap(bitmapData)) as Bitmap;
			shape = new Shape();
			initialize();
		}
		public function initialize():void {
			addEventListener(Event.ENTER_FRAME, draw);
		}
		private function draw(e:Event):void {
			var s:Stage = stage;
			var sw:Number = s.stageWidth;
			var sh:Number = s.stageHeight;
			shape.graphics.clear();
			bitmapData.fillRect(bitmapData.rect, 0xffffff);
			// cache.fillRect(bitmapData.rect, 0xffffff);
			drawTriangle(0, 0, sw, 0, 0, sh, 0);
			drawTriangle(sw, sh, sw, 0, 0, sh, 0);
			// cache.draw(shape);
			// bitmapData.copyPixels(cache, bitmapData.rect, new Point(0, 0));
			bitmapData.draw(shape);
		}
		private function drawTriangle(ax:Number, ay:Number, bx:Number, by:Number, cx:Number, cy:Number, level:int):void {
			var g:Graphics = shape.graphics;
			g.beginFill(0xffffff);
			g.lineStyle(1, 0x000000);
			g.moveTo(ax, ay);
			g.lineTo(bx, by);
			g.lineTo(cx, cy);
			g.lineTo(ax, ay);
			g.endFill();
			if (level == LEVEL_MAX) return;
			var ab:Number = Util.getRandomRange(0.1, 0.9);
			var ac:Number = Util.getRandomRange(0.1, 0.9);
			var bc:Number = Util.getRandomRange(0.1, 0.9);
			var abax_ab:Number = ax + (bx - ax) * ab;
			var abay_ab:Number = ay + (by - ay) * ab;
			var acax_ac:Number = ax + (cx - ax) * ac;
			var acay_ac:Number = ay + (cy - ay) * ac;
			var bcbx_bc:Number = bx + (cx - bx) * bc;
			var bcby_bc:Number = by + (cy - by) * bc;
			level++;
			drawTriangle(
				ax, ay,
				abax_ab, abay_ab,
				acax_ac, acay_ac,
				level
			);
			drawTriangle(
				bx, by,
				abax_ab, abay_ab,
				bcbx_bc, bcby_bc,
				level
			);
			drawTriangle(
				cx, cy,
				acax_ac, acay_ac,
				bcbx_bc, bcby_bc,
				level
			);
		}
	}
}
internal class Util {
	public static function getRandomRange(min:Number, max:Number):Number {
		return (max - min) * Math.random() + min;
	}
}