forked from: code on 2008-12-18
// forked from szktkhr's code on 2008-12-18
package {
import flash.display.*;
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 = 5; 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.*;
import flash.events.Event;
import flash.geom.Point;
import flash.filters.*;
class Line extends Sprite {
private var vx:Number;
private var vy:Number;
private var vs:Number;
private var camera:Point;
private var brown:Point;
private var r:Number;
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();
r = Math.random() * 360;
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, r+=10);
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;
private var r:Number;
private var blur:BlurFilter;
public function Tail(targetObject:DisplayObject, camera:Point, ro:Number) {
target = targetObject;
this.camera = camera;
r = ro;
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 = 40;
graphics.beginFill(0x99cc66);
//graphics.drawCircle(0, 0, radius);
graphics.drawCircle(-radius / 2, 0, radius / 3);
graphics.drawCircle(-radius / 2, 0, radius / 6);
graphics.drawCircle(0, -radius / 2, radius / 3);
graphics.drawCircle( radius / 2, 0, radius / 3);
graphics.drawCircle( radius / 2, 0, radius / 6);
graphics.drawCircle(0, radius / 2, radius / 3);
graphics.endFill();
graphics.beginFill(0xcccc66);
graphics.drawCircle(0, radius / 2, radius / 3);
graphics.endFill();
rotation = r;
blendMode = BlendMode.MULTIPLY;
blur = new BlurFilter();
blur.blurX = 2;
blur.blurY = 2;
filters = [blur];
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.19;
scaleY /= 1.19;
rotation += 30;
blur.blurX += 1;
blur.blurY += 1;
filters = [blur];
if (width < 10) tellRemoveToParent();
}
private function tellRemoveToParent():void {
var p:Main = parent as Main;
p.remove(this);
}
}