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

Tomehane

ほっとくと重くなるよたすけて
/**
 * Copyright miyaoka ( http://wonderfl.net/user/miyaoka )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/v68s
 */

/*
ほっとくと重くなるよたすけて
*/
package  
{
	import flash.display.Sprite;
	import flash.display.BitmapData;
	import flash.display.Bitmap;
	import flash.utils.Timer;
	import flash.events.TimerEvent;
	import flash.events.MouseEvent;
	import flash.geom.ColorTransform;

	[SWF(width = "465", height = "465", backgroundColor = 0, frameRate = "60")]
	public class Tomehane
	extends Sprite
	{
		private const W:Number = 465;
		private const H:Number = 465;
		public function Tomehane() 
		{
			//
			var bmd:BitmapData = new BitmapData(W,H,true,0x00FFFFFF)
			var container:Container = new Container(bmd);
			//
			var bmp:Bitmap = new Bitmap(bmd);
			
			
			//
			var timer:Timer = new Timer(100);
			timer.addEventListener(TimerEvent.TIMER, function ():void 
			{
				bmd.colorTransform(bmd.rect, new ColorTransform(1, 1, 1, 0.9));
			});
//			timer.start();
			//
			stage.addEventListener(MouseEvent.MOUSE_DOWN,function ():void 
			{
				timer.running ? timer.stop() : timer.start();
			});
			addChild(bmp);
			addChild(container);

		}

	}
	
}
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.filters.GlowFilter;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.events.Event;
//import fl.motion.BezierSegment;
import flash.utils.Timer;
import flash.events.TimerEvent;
	

class Container
extends Sprite
{
	private var bmd:BitmapData;
	public function Container(bmd_:BitmapData):void 
	{
		bmd = bmd_;
		var num:uint = 3;
		while (num--) add(null);

	}
	private function add(e:Event):void 
	{
		var startPt:Point;
		if (e != null)
		{
			var lastCb:CircuitBezier = e.target as CircuitBezier;
			startPt = lastCb.ptEnd;
//			removeChild(lastCb);
			lastCb.removeEventListener("complete", add);
			lastCb = null;
		}
		else
		{
			startPt = new Point(Math.random() * bmd.width, Math.random() * bmd.height);
		}
		var cb:CircuitBezier;
		cb = new CircuitBezier(bmd, 
		startPt,
		new Point(Math.random()* bmd.width, Math.random()*bmd.height),
		new Point(Math.random() * bmd.width, Math.random() * bmd.height)
		);
		cb.addEventListener("complete", add);
//		addChild(cb);
		
	}
}

import flash.filters.GradientGlowFilter;
class CircuitBezier
extends Sprite
{
//	private var bs:BezierSegment;
	private var timer:Timer = new Timer(100);
	private var step:uint = 100;
	private var i:uint = 0;
	private var bmd:BitmapData;
	public var ptStart:Point;
	public var ptAnc:Point;
	public var ptEnd:Point;
	public function CircuitBezier(bmd_:BitmapData, pt0:Point, pt1:Point, pt2:Point):void 
	{
		bmd = bmd_;
		ptStart = pt0;
		ptAnc = pt1;
		ptEnd = pt2;
		timer.addEventListener(TimerEvent.TIMER, update);
		timer.start();
		filters = [
//		new GlowFilter(0xFFFFFF, 1, 20, 20, 2, 2)
		];
	}
	public function update(evt:TimerEvent):void 
	{
		var pt0:Point = getValue(i / step);
		var pt1:Point = getValue((i +1) / step);
		//
		
		timer.removeEventListener(TimerEvent.TIMER, update);
		//
		if (i + 1 < step)
		{			
			//-PI to PI
			var phi:Number = getPhi(pt0, getValue((i +2) / step), pt1);
			
			//0 to 1
			phi = Math.abs(phi) / Math.PI;

			timer = new Timer((1 - phi) * 1000);
			timer.start();
			timer.addEventListener(TimerEvent.TIMER, update);
			

		}
		else
		{
			timer.stop();
			timer = null;
			var e:Event = new Event("complete");	
			dispatchEvent(e);
			return;
		}
		
		var g:Graphics = graphics;
		g.clear();
		g.moveTo(pt0.x, pt0.y);
		g.beginFill(0xFFFFFF);
		g.lineStyle(Math.min(20, (1 - phi) * 1500), 0xFFFFFF);
		g.lineTo(pt1.x, pt1.y);
		
		bmd.draw(this);
		
//		g.drawCircle(pt1.x, pt1.y, 5);
		i++;
	}
	private function getValue(num:Number):Point
	{
		return new Point(
			Math.pow(1 - num, 2) * ptStart.x + 2 * num *(1 - num) * ptAnc.x + Math.pow(num, 2) * ptEnd.x,
			Math.pow(1 - num, 2) * ptStart.y + 2 * num *(1 - num) * ptAnc.y + Math.pow(num, 2) * ptEnd.y
		);
	}
	private function getPhi(pt1:Point, pt2:Point, pt0:Point):Number
	{

		pt1 = pt1.subtract(pt0);
		pt2 = pt2.subtract(pt0);

		return Math.atan2(pt1.x * pt2.y - pt1.y * pt2.x, pt1.x * pt2.x + pt1.y * pt2.y);
	}
}