图片三维粒子化及运动

三维粒子 everyinch 4731℃ 0评论

package{
import __AS3__.vec.Vector;

import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.display.PixelSnapping;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.geom.PerspectiveProjection;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.net.URLRequest;
import flash.utils.getTimer;

import net.everyinch.geom.Particle;

[SWF(width=”800″,height=”600″,frameRate=”32″,backgroundColor=”0x000000″)]
public class ParticleImage1 extends Sprite{
private const PI2:Number = Math.PI*2;
private var bmpd:BitmapData = new BitmapData(800,600,false,0);
private var buffer:Vector. = new Vector.(800*600,true);
private var focalLength:Number;
private var particle:Particle = new Particle();

private var phi:Number = -Math.PI/4;
private var theta:Number = Math.PI*3/2;

public function ParticleImage1(){
init();
}

private function init():void{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.frameRate = 32;
//stage.quality = StageQuality.LOW;
stage.fullScreenSourceRect = new Rectangle(0,0,550,400);

var perspectiveProjection:PerspectiveProjection = new PerspectiveProjection();
perspectiveProjection.fieldOfView = 60;
perspectiveProjection.projectionCenter = new Point(400,300);
focalLength = perspectiveProjection.focalLength;

addChild(new Bitmap(bmpd,PixelSnapping.NEVER,false));

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoaded);
loader.load(new URLRequest(“assets/Flower.jpg”));
}

private function onLoaded(e:Event):void{
var image:Bitmap = Bitmap(e.target.content);
createParticles(image);
addEventListener(Event.ENTER_FRAME,onEnterframe);
}

private function createParticles(image:Bitmap):void{
var sampling:Number = 1;
var spread:Number = 1;
var p:Particle = particle;
for(var i:int=0;i -1){
buffer[n] = 0x000000;
}
var p:Particle = particle;
do{
var red:Number = Number(p.color >> 16 & 0xFF);
var green:Number = Number(p.color >> 8 & 0xFF);
var blue:Number = Number(p.color & 0xFF);
var lum:Number = 0.2126*red + 0.7152*green + 0.0722*blue
p.z = zFactor*lum*lum-recess;
var u:Number = M11*p.x + M12*p.y + cosp*p.z;
f = fadeRate*(u-fadeZ);
if(f < minFade){ f = minFade; } else if(f > 1){
f = 1;
}
m = fLen/(fLen-u)
ix = int((-sint*p.x+cost*p.y)*m+cx);
iy = int((M31*p.x+M32*p.y+sinp*p.z)*m+cy);
i = int(ix+iy*bmpd.width);
color = (f*p.color << 16) | (f*p.color << 8) | (f*p.color & 0xFF); if(i > 0 && i < 480000){ buffer[i] = p.color; } p = p.next; }while(p); bmpd.lock(); bmpd.setVector(bmpd.rect,buffer); bmpd.unlock(bmpd.rect); } } } [/code]

分享&收藏

转载请注明:陈童的博客 » 图片三维粒子化及运动

喜欢 (0)
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
(1)个小伙伴在吐槽
  1. so coooooool!
    雨人2014-01-21 20:27 回复
'; } if( dopt('d_footcode_b') ) echo dopt('d_footcode'); ?>