forked from: s3d
/**
* Copyright lizhi ( http://wonderfl.net/user/lizhi )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/oitv
*/
// forked from lizhi's s3d
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BlendMode;
import flash.display.Sprite;
import flash.events.Event;
import flash.filters.BlurFilter;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Vector3D;
import flash.utils.Dictionary;
/**
* ...
* @author lizhi http://game-develop.net/
*/
[SWF(frameRate=60,width=465,height=465)]
public class Test3D extends Sprite
{
private var vs:Vector.<Vector3D> = new Vector.<Vector3D>;
private var v2s:Dictionary = new Dictionary;
private var shadow:BitmapData;
public function Test3D()
{
shadow = new BitmapData(32, 32, true, 0);
var pen:Sprite = new Sprite();
pen.graphics.beginFill(0xffffff);
pen.graphics.drawCircle(16, 16, 10);
pen.graphics.endFill();
pen.filters = [new BlurFilter(4,4,3)];
shadow.draw(pen);
x = stage.stageWidth / 2;
y = stage.stageHeight / 2;
for (var i:int = 0; i < 100; i++ ) {
var v:Vector3D = new Vector3D(0, 0, 100 + i * 10);
var s:Sprite = new Sprite;
var b:Bitmap = new Bitmap(shadow,"auto",true);
b.transform.colorTransform = new ColorTransform(Math.random(), Math.random(), Math.random());
s.addChild(b);
s.blendMode = BlendMode.ADD;
b.x = -b.width / 2;
b.y = -b.height / 2;
v2s[v] = s;
vs.push(v);
addChildAt(s, 0);
}
addEventListener(Event.ENTER_FRAME, enterFrame);
graphics.clear();
graphics.beginFill(0);
graphics.drawRect(-this.x, -this.y, 465, 465);
graphics.endFill();
}
private function enterFrame(e:Event):void
{
var lv:Vector3D = new Vector3D(mouseX, mouseY);
for each(var v:Vector3D in vs) {
v.x += (lv.x - v.x) * .3;
v.y += (lv.y - v.y) * .3;
lv = v;
var fz:Number = 100 / v.z;
var x:Number = v.x * fz;
var y:Number = v.y * fz;
var r:Number = 30 * fz;
var s:Sprite = v2s[v];
s.x = x;
s.y = y;
s.scaleX = s.scaleY = 2 * r / shadow.width;
}
}
}
}