粒子效果2

import flash.geom.*;
[SWF(width = 465, height = 465, backgroundColor = 0x0, frameRate = 30)]
 var m:Matrix3D,vm:Matrix3D = new Matrix3D(),p:Object,pp:PerspectiveProjection = new PerspectiveProjection(),pm:Matrix3D=pp.toMatrix3D(),vins:Vector.<Number> = new Vector.<Number>(),vouts:Vector.<Number> = new Vector.<Number>(),uvts:Vector.<Number> = new Vector.<Number>(),v2ds:Vector.<Number> = new Vector.<Number>(),particles:Array = [];
addEventListener("enterFrame", function():void{
if (Math.random()<0.05) {var c2:int = 400 * Math.random();
var v2:Vector3D = new Vector3D((Math.random()-0.5)*400,(Math.random()-0.5)*400,(Math.random()-0.5)*400,Math.random()*0xffffff);
while (c2-- > 0){(m = new Matrix3D(Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,0, 0, (Math.random()*.2+0.8) * 5,1]))).appendRotation(360 * Math.random(), Vector3D.X_AXIS);
        m.appendRotation(360 * Math.random(), Vector3D.Y_AXIS);
        var v:Vector3D = m.transformVector(new Vector3D);
        particles.push({tails:[],energy:Math.random() * 5,v:v,position:v2,color:v2.w,deceleration:.95,gravity:.05,length:2});}}
(vm=new Matrix3D(Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,0, 200, -550,1]))).appendRotation(mouseX/10, Vector3D.Y_AXIS,vm.position);
vm.appendRotation(-mouseY/10, Vector3D.X_AXIS,vm.position);
vm.invert();
graphics.clear();
for (var i:int = particles.length - 1; i >= 0; i--){(p = particles[i]).v.scaleBy(p.deceleration);
        p.v.y += p.gravity;
        p.position= p.position.add(p.v);
        p.energy *= p.deceleration;
        if (p.energy < 0.05) { particles.splice(i, 1);
        } else {p.v2d = Utils3D.projectVector(pm, (p.vposition = vm.transformVector(p.position)));
                graphics.lineStyle(400 / p.v2d.w, p.color);
                graphics.moveTo(p.v2d.x, p.v2d.y);
                for (var j:int = p.tails.length - 1,c:int=0,tc:int=4; j >= 0; j--,c++) {
                        if (c>p.energy*tc) {p.tails.splice(j, 1); continue;}
                        var v2d:Vector3D = Utils3D.projectVector(pm, vm.transformVector(p.tails[j]));
                        graphics.lineStyle(500 / p.v2d.w, p.color,(p.energy*tc-c)/p.energy*tc);
                        graphics.lineTo(v2d.x, v2d.y);}
                if (p.tails[0]) {if (Math.sqrt((p.tails[p.tails.length - 1].x-p.position.x)*(p.tails[p.tails.length - 1].x-p.position.x)+(p.tails[p.tails.length - 1].y-p.position.y)*(p.tails[p.tails.length - 1].y-p.position.y)+(p.tails[p.tails.length - 1].z-p.position.z)*(p.tails[p.tails.length - 1].z-p.position.z))>p.length) {p.tails.push(p.position.clone());}}else {p.tails.push(p.position.clone());}}}});
x =y = 228;

posted on 2012-12-01 14:50  主人的成长  阅读(186)  评论(0编辑  收藏  举报

导航