forked from: ワープっぽいなにか
ワープっぽく・・・見える?w
mouseMove : move perspective point
mouseDown : speed up
mouseUp : speed down
// forked from ton's ワープっぽいなにか
/*
ワープっぽく・・・見える?w
mouseMove : move perspective point
mouseDown : speed up
mouseUp : speed down
*/
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.PerspectiveProjection;
import flash.geom.Point;
[SWF(width=465, height=465, backgroundColor=0x000000)]
public class Warp extends Sprite {
private const W:int = stage.stageWidth;
private const H:int = stage.stageHeight;
private const R:int = 500;
private const PI:Number = Math.PI;
private var perspective:PerspectiveProjection;
public function Warp() {
perspective = this.transform.perspectiveProjection;
perspective.fieldOfView = 90;
addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownHandler);
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUpHandler);
x = 230;
y = 230;
}
private function onMouseDownHandler(e:MouseEvent):void { Rect3D.moveZ = 10; }
private function onMouseUpHandler(e:MouseEvent):void { Rect3D.moveZ = 8; }
private function onEnterFrameHandler(e:Event):void {
perspective.projectionCenter = new Point(mouseX+x, mouseY+y);
var n:int = Rect3D.moveZ / 6;
for (var i:int = 0; i < n; i++){
var rect:Rect3D = new Rect3D(Math.random() * 0xffffff, 20);
var rad:Number = Math.random() * 2 * PI;
rect.x = R * Math.cos(rad);
rect.y = R * Math.sin(rad);
rect.z = Math.random() * 10 + 30;
rect.rotationX = 180-Math.atan2(rect.y , rect.x ) * 180 / PI;
rect.rotationY = 90;
addChild(rect);
}
}
}
}
import flash.display.Sprite;
import flash.events.Event;
class Rect3D extends Sprite {
public static var moveZ:int = 8;
public function Rect3D(color:uint, size:int) {
graphics.beginFill(color);
graphics.drawRect( -size / 2, -size / 2, size, size);
graphics.endFill();
addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
}
private function onEnterFrameHandler(e:Event):void {
this.z -= moveZ;
if (this.z <= 0) {
parent.removeChild(this);
removeEventListener(e.type, arguments.callee);
}
}
}