Beautifl - Flash Gallery

Thumbnail : code on 2008-12-18
code on 2008-12-18
szktkhr 2009-08-27 All rights reserved

再生するにはFlash Playerが必要です。デスクトップのブラウザでご覧ください。

package {
	import flash.display.Sprite;
	import flash.display.DisplayObject;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.geom.Point;
	
	public class Main extends Sprite {
		private var camera:Point;
		private var brown:Point;
		
		public function Main() {
			camera = new Point();
			brown = new Point();
			addEventListener(Event.ADDED_TO_STAGE, initialize);
			addEventListener(Event.ENTER_FRAME, transitionCamera);
			addEventListener(Event.ENTER_FRAME, gogoBrown);
		}
		private function initialize(event:Event):void {
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			brown.x = Math.random() * stage.stageWidth;
			brown.y = Math.random() * stage.stageHeight;
			
			for (var i:uint = 25; i-- > 0;) {
				addChild(new Line(camera, brown));
			}
		}
		private function transitionCamera(event:Event):void {
			camera.x += Math.random() * 2 > 1? (Math.random() * 20) / 20: -(Math.random() * 20) / 20;
			camera.y += Math.random() * 2.5 > 1? (Math.random() * 20) / 20: -(Math.random() * 20) / 20;
			camera.x /= 1.01;
			camera.y /= 1.01;
		}
		private function gogoBrown(event:Event):void {
			brown.x += Math.random() * 2 > 1? (Math.random() * 10): -(Math.random() * 10);
			brown.y += Math.random() * 2 > 1? (Math.random() * 10): -(Math.random() * 10);
			if (brown.x < 0 || brown.x > stage.stageWidth) brown.x = Math.random() * stage.stageWidth;
			if (brown.y < 0 || brown.y > stage.stageHeight) brown.y = Math.random() * stage.stageHeight;
		}
		public function remove(child:DisplayObject):void {
			removeChild(child);
		}
	}
	
}
import flash.display.Sprite;
import flash.display.DisplayObject;
import flash.events.Event;
import flash.geom.Point;
class Line extends Sprite {
	private var vx:Number;
	private var vy:Number;
	private var vs:Number;
	private var camera:Point;
	private var brown:Point;
	public function Line(wvp:Point, b:Point) {
		camera = wvp;
		brown = b;
		vs = Math.random() * 50 + 100;
		vx = 0;
		vy = 0;
		addEventListener(Event.ADDED_TO_STAGE, initialize);
		addEventListener(Event.REMOVED_FROM_STAGE, uninitialize);
	}
	private function initialize(event:Event):void {
		graphics.beginFill(0x000000);
		graphics.drawCircle(0, 0, 2);
		graphics.endFill();
		x = Math.random() * stage.stageWidth;
		y = Math.random() * stage.stageHeight;
		addEventListener(Event.ENTER_FRAME, cruising);
		addEventListener(Event.ENTER_FRAME, tail);
	}
	private function uninitialize(event:Event):void {
		removeEventListener(Event.ADDED_TO_STAGE, initialize);
		removeEventListener(Event.REMOVED_FROM_STAGE, uninitialize);
		removeEventListener(Event.ENTER_FRAME, cruising);
		removeEventListener(Event.ENTER_FRAME, tail);
	}
	private function cruising(event:Event):void {
		vx += (brown.x - x) / vs;
		vy += (brown.y - y) / vs;
		vx /= 1.005;
		vy /= 1.005;
		x += vx / 1;
		y += vy / 1;
	}
	private function tail(event:Event):void {
		var tail:Tail = new Tail(this, camera);
		tail.x = x;
		tail.y = y;
		parent.addChild(tail);
	}
}
class Tail extends Sprite {
	private var vx:Number;
	private var vy:Number;
	private var target:DisplayObject;
	private var camera:Point;
	public function Tail(targetObject:DisplayObject, camera:Point) {
		target = targetObject;
		this.camera = camera;
		addEventListener(Event.ADDED_TO_STAGE, initialize);
		addEventListener(Event.REMOVED_FROM_STAGE, uninitialize);
	}
	private function initialize(event:Event):void {
		x = target.x;
		y = target.y;
		var radius:uint = 5;
		graphics.beginFill(0x000000);
		graphics.drawCircle(-radius / 2, -radius / 2, radius);
		graphics.drawCircle(-radius / 2, -radius / 2, radius / 3);
		graphics.endFill();
		addEventListener(Event.ENTER_FRAME, motion);
	}
	private function uninitialize(event:Event):void {
		removeEventListener(Event.ADDED_TO_STAGE, initialize);
		removeEventListener(Event.REMOVED_FROM_STAGE, uninitialize);
		removeEventListener(Event.ENTER_FRAME, motion);
	}
	private function motion(event:Event):void {
		x += camera.x;
		y += camera.y;
		scaleX /= 1.09;
		scaleY /= 1.09;
		
		if (width < 1) tellRemoveToParent();
	}
	private function tellRemoveToParent():void {
		var p:Main = parent as Main;
		p.remove(this);
	}
}