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

tree

Get Adobe Flash player
by demouth 18 Jan 2009
// write as3 code here..
package  
{
	import flash.display.StageScaleMode;
	import flash.display.StageAlign;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	
	public class Main extends Sprite
	{
		public var b:Bitmap;
		public var bd:BitmapData;
		
		[SWF(width="465", height="465", backgroundColor="0x000000", frameRate="31")]
		public function Main() 
		{
			var mainSp:Sprite = new Sprite();
			this.addChild(mainSp);
			//mainSp.scaleX = mainSp.scaleY = 0.5;
			
			
			this.stage.scaleMode = StageScaleMode.NO_SCALE;
			this.stage.align     = StageAlign.TOP_LEFT;
			
			//this.bd = new BitmapData(this.stage.stageWidth * 2, this.stage.stageHeight * 2);
			this.bd = new BitmapData(this.stage.stageWidth, this.stage.stageHeight);
			this.b = new Bitmap(this.bd);
			this.b.smoothing = true;
			mainSp.addChild(this.b);
			
			var l2:Line = new Line(this.b,this.bd);
			l2.init();
			l2.positionX = mainSp.stage.stageWidth / 2;
			l2.positionY = mainSp.stage.stageHeight;
			l2.addAccele(0 , -3);
			mainSp.addChild(l2);
		}
		
	}
	
}


import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.Event;

class Line extends Sprite
{
	public var positionX:Number = 0;
	public var positionY:Number = 0;
	public var positionX_old:Number = 0;
	public var positionY_old:Number = 0;
	public var speedX:Number = 0;
	public var speedY:Number = 0;
	public var acceleX:Number = 0;
	public var acceleY:Number = 0;
	public var friction:Number = 0.99;
	public var life:Number = 3;
	public var color:Number = 0;
	
	public var b:Bitmap;
	public var bd:BitmapData;
	
	private var isChild:Boolean = false;
	
	public function Line(b:Bitmap,bd:BitmapData)
	{
		this.b = b;
		this.bd = bd;
	}
	
	public function init():void
	{
		this.addEventListener(Event.ENTER_FRAME , onEnterFrame);
	}
	
	public function addAccele(x:Number , y:Number):void
	{
		this.acceleX = x;
		this.acceleY = y;
	}
	
	private function onEnterFrame(e:Event):void
	{
		//スピード計算
		this.calcSpeed();
		
		//たまに加速度を追加
		this.randomAddAccele();
		
		//新しいLineを作る
		if (
			Math.random() > 0.96
			&&
			( Math.abs(this.speedX) + Math.abs(this.speedY) ) > 0.5 //一定のスピードがあるものだけ
		) this.birth();
		
		//描画
		this.draw();
		
		//スピードが遅くなったら
		if ( ( Math.abs(this.speedX) + Math.abs(this.speedY) ) < 0.1 )
		{
			this.removeEventListener(Event.ENTER_FRAME , onEnterFrame);
		}
		
		this.color += 0.3;
	}
	
	/**
	 * 新しいLineを作成する
	 */
	private function birth():void
	{
		var newChild:Line = this.getCopySelf();
		newChild.life--;
		if (newChild.life >= 0)
		{
			newChild.isChild = true;
			//newChild.acceleX = this.speedX * Math.random() * 0.2;
			//newChild.acceleY = this.speedY * Math.random() * 0.2;
			this.addChild(newChild);
			newChild.init();
		}
		else
		{
			newChild = null;
		}
	}
	
	/**
	 * 自分自身をコピーしたものを返す
	 * @return Line
	 */
	private function getCopySelf():Line
	{
		var newChild:Line = new Line(this.b,this.bd);
		newChild.positionX = this.positionX;
		newChild.positionY = this.positionY;
		newChild.speedX = this.speedX;
		newChild.speedY = this.speedY;
		newChild.acceleX = this.acceleX;
		newChild.acceleY = this.acceleY;
		newChild.friction = this.friction;
		newChild.life = this.life;
		newChild.color = this.color;
		
		return newChild;
	}
	
	/**
	 * たまに加速度を追加する。
	 */
	private function randomAddAccele():void
	{
		var addX:Number = 0;
		var addY:Number = 0;
		var power:Number = Math.abs(this.speedX) + Math.abs(this.speedY);
		addX = Math.random() * (power * 0.2);
		addY = Math.random() * (power * 0.2);
		addX = addX - Math.random() * 2 * addX;
		addY = addY - Math.random() * 2 * addY;
		if (Math.random() > 0.5) addX = 0;
		if (Math.random() > 0.5) addY = 0;
		
		this.speedX += addX;
		this.speedY += addY;
	}
	
	/**
	 * スピード・加速度・抵抗などを計算する。
	 */
	private function calcSpeed():void
	{
		//加速度加算
		this.speedX += this.acceleX;
		this.speedY += this.acceleY;
		
		//加速度を0に戻す
		this.acceleX = 0;
		this.acceleY = 0;
		
		//抵抗を乗算
		this.speedX *= this.friction;
		this.speedY *= this.friction;
		
		//移動する前の位置を保持
		this.positionX_old = this.positionX;
		this.positionY_old = this.positionY;
		
		//移動
		this.positionX += this.speedX;
		this.positionY += this.speedY;
	}
	
	/**
	 * 描画する
	 */
	private function draw():void
	{
		var g:Graphics = this.graphics;
		var thick:Number = 1;
		var color:uint = int(this.color) << 16 | int(this.color) << 8 | int(this.color);
		
		thick = this.life * 4;
		g.clear();
		g.moveTo(this.positionX_old , this.positionY_old);
		g.lineStyle(thick , color , 1);
		g.lineTo(this.positionX , this.positionY);
		
		this.bd.draw(this);
	}
}