flash on 2015-7-4
/**
* Copyright J.J ( http://wonderfl.net/user/J.J )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/9xb3
*/
package{
import flash.display.Graphics;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.Sprite;
import flash.text.AntiAliasType;
import flash.text.TextFormatAlign;
import flash.text.TextFormat;
import flash.text.TextField;
public class ThreeD extends Sprite{
public var m:Vc3;
public var h:int;
public var w:int;
public var oobj:Obj3D;
public var n:int;
public var isDown:Boolean;
public var targ:Obj3D;
public var Zp:Number;
public var ps:Vector.<Obj3D>;
public function ThreeD(){
var ar:Vc3=new Vc3(4,5,6);
w = stage.stageWidth;
h = stage.stageHeight;
ps = new Vector.<Obj3D>();
Vc3.init(w / 2, h / 2);
m = new Vc3(0, 0, 0);
drawBack();
oobj = new Obj3D(new Vc3(200, 200,( Math.random()*400)), 25);
oobj.update();
this.addEventListener(Event.ENTER_FRAME, loop);
n = 1;
var o:Obj3D = new Obj3D(new Vc3( w/2+Math.random()*30, h/2+Math.random()*30,25),Math.random()*25);
ps.push(o);
stage.addEventListener(MouseEvent.MOUSE_WHEEL, wheel);
}
private function drawBack():void {
this.graphics.beginFill(0xffffff);
this.graphics.drawRect(0, 0, w, h);
this.graphics.endFill();
}
private function wheel(e:MouseEvent):void
{
var dlt:Number = e.delta;
for (var i:int=0;i<n;i++) {
var o:Obj3D = ps[i];
o.v.z -= dlt;
}
}
private function loop(e:Event):void
{
//oobj.loc.z--;
var l:Obj3D = ps[ps.length - 1];
var ang:Number = Math.random() * (Math.PI * 2);
var o3:Obj3D = new Obj3D(new Vc3(l.x +Math.cos(ang)*(Math.random()*15), l.y + Math.sin(ang)*(Math.random()*15), l.z+Math.random()*15
));
this.addChild(o3);
ps.push(o3);
n = ps.length;
if (n > 50) {
this.removeChildAt(0);
}
if(n>500) ps.shift();
n = ps.length;
var x:Number = l.y/2.5;
var y:Number = l.x / 2.5;
var z:Number = 0;
var mm:Vc3 = new Vc3(x, y, z);
var m2:Vc3 = m.to(mm);
for (var i:int=0;i<n;i++) {
o= ps[i];
o.v.x += m2.x*.8;
o.v.y += m2.y *.8;
o.v.z += Math.random()/10;
}
if (Math.random() < .02) {
// trace("shod");
var k:int = 20;
if (Math.random() < .5) k *=-1;
for (i=0;i<n;i++) {
o= ps[i];
o.v.z += k;
}
}
var o:Obj3D = ps[ps.length-1];
var g:Graphics = this.graphics
g.clear();
drawBack();
var t :Number = 20;
g.lineStyle(t,0);
g.moveTo(o.x, o.y);
i= ps.length - 1;
var angl:Number = (Math.PI / 150);
while(i>-1){
o = ps[i--];
o.loc.x += o.v.x;
o.loc.y += o.v.y;
o.loc.z += o.v.z;
o.update();
t *= .95;
if (o.visible == false) {
g.lineStyle(t, 0, 0);
}else {
g.lineStyle(t, 0, .1+t);
}
g.lineTo(o.x, o.y);
o.v.x *= .9;
o.v.y *= .9;
o.v.z *= .9;
var cosb:Number = Math.cos(angl);
var sinb:Number = Math.sin(angl);
var _qx:Number = o.loc.x- Vc3.O.x;
var _qy:Number = o.loc.y- Vc3.O.y;
var _qz:Number = o.loc.z-Vc3.O.z;
var _qxx:Number = _qx * cosb - _qz * sinb;
var _qzz:Number = _qz * cosb + _qx * sinb;
o.loc.x = Vc3.O.x+_qxx;
o.loc.z = 0 + _qzz;
}
m = mm;
}
}
}
import flash.text.TextFormatDisplay;
import flash.text.AntiAliasType;
import flash.text.TextFormat;
import flash.text.TextField;
import flash.display.Sprite;
class Vc3 {
public static var O:Vc3;
public var x:Number=0;
public var y:Number=0;
public var z:Number = 0;
public static function init(x:Number, y:Number):void {
O = new Vc3(x, y, 0);
}
public function Vc3(x:Number, y:Number, z:Number) {
this.z = z;
this.x = x;
this.y = y;
}
public function to(v:Vc3):Vc3 {
return new Vc3(v.x - this.x, v.y - this.y, v.z - this.z);
}
}
class Obj3D extends Sprite {
public var loc:Vc3;
public var delt:Vc3;
public var v:Vc3;
public const fl:Number=250;
public const arry:Array=[".<Number>","Math.cos","Graphics","public","Vector.<type>","Obj3D","Math.sin"]
public function Obj3D(loc:Vc3, r:Number = 25) {
this.loc = loc;
this.v = new Vc3(0, 0, 0);
super();
/*this.graphics.beginFill(0);
this.graphics.drawCircle(0, 0, r);
this.graphics.endFill();*/
var tx:TextField = new TextField();
var txf:TextFormat = new TextFormat();
txf.font = "Adobe Arabic";
txf.size = 18;
//tx.type = TextFieldType.DYNAMIC;
tx.mouseEnabled = false;
tx.defaultTextFormat = txf;
tx.antiAliasType = AntiAliasType.NORMAL;
tx.text = arry[int(arry.length * Math.random() )];
tx.textColor = 0x101010;
tx.selectable = false;
this.addChild(tx);
//tx.x = -tx.width / 2;
update();
}
public function update() :void{
var p:Vc3 = this.loc;
if(p.z>-fl){
var k:Vc3 = Vc3.O.to(p);
var sc:Number = fl / (fl + p.z);
this.scaleX = this.scaleY = sc;
this.x = Vc3.O.x + k.x * sc;
this.y = Vc3.O.y + k.y * sc;
this.visible = true;
this.alpha = sc;
} else {
this.visible = false;
}
}
}