forcemap
一応3D
/**
* Copyright about ( http://wonderfl.net/user/about )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/yKA5
*/
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BitmapDataChannel;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.filters.BlurFilter;
import flash.geom.ColorTransform;
import flash.geom.Rectangle;
import flash.utils.Timer;
[SWF(width="500",height="500",backgroundColor="0")]
public class particle5 extends Sprite
{
private var bmpd:BitmapData;
private var forcemap:BitmapData;
private var bmp:Bitmap;
private var colortf:ColorTransform;
private var particles:Vector.<Particle>;
private var blur:BlurFilter = new BlurFilter(4,4,1);
private var timer:Timer = new Timer(8000);
public function particle5()
{
bmpd = new BitmapData(500,500,false,0);
forcemap = new BitmapData(500,500,false,0);
bmp = new Bitmap(bmpd);
addChild(bmp);
// addChild(new Bitmap(forcemap));
//残像
colortf = new ColorTransform(0,.79,.99,1);
onMouseClick();
addEventListener(Event.ENTER_FRAME,onEnterFrame);
stage.addEventListener(MouseEvent.CLICK,onMouseClick);
timer.start();
timer.addEventListener(TimerEvent.TIMER,onTimerEvent);
}
private function onEnterFrame(e:Event):void{
bmpd.colorTransform(new Rectangle(0,0,500,500),colortf);
bmpd.applyFilter(bmpd,bmpd.rect,bmpd.rect.topLeft,blur);
var len:Number = particles.length;
bmpd.lock();
while(len--){
var p:Particle = particles[len];
//色のピクセルを取得
var color:Number = forcemap.getPixel(p.xx,p.yy);
//赤
var r:int = color >> 16 & 0xff;
//緑
var g:int = color >> 8 & 0xff;
//青
var b:int = color & 0xff;
p.ax = (r-128)*0.006;
p.ay = (g-128)*0.006;
p.az = (b-128)*0.006;
p.vx += p.ax;
p.vy += p.ay;
p.vz += p.az;
p.xx += p.vx;
p.yy += p.vy;
p.zz += p.vz;
p.ax *= 0.98;
p.ay *= 0.98;
p.az *= 0.98;
p.vx *= 0.93;
p.vy *= 0.93;
p.vz *= 0.93;
bmpd.fillRect(new Rectangle(p.xx,p.yy,2,2),0xffffff);
//はみ出した時の処理
if(p.xx < 0) p.xx = 500+p.xx;
else if(p.xx > 500) p.xx = p.xx-500;
if(p.yy < 0) p.yy = 500+p.yy;
else if(p.yy > 500) p.yy = p.yy-500;
if(p.zz < 0) p.zz = 500+p.zz;
else if(p.zz > 500) p.zz = p.zz-500;
}
bmpd.unlock();
}
private function onMouseClick(e:MouseEvent = null):void{
// timer.stop();
timer.reset();
timer.start();
particles = new Vector.<Particle>;
for(var i:int=0;i<10000;i++){
var p:Particle = new Particle();
p.xx = Math.random()*500;
p.yy = Math.random()*500;
p.zz = Math.random()*500;
p.vx = p.vy = p.vz = p.ax = p.ay = p.az =0;
particles.push(p);
}
forcemap.perlinNoise(200,200,4,Math.floor(Math.random()*0xffff),false,true,3|1|4|0);
}
private function onTimerEvent(e:TimerEvent):void{
trace("aaaa");
forcemap.perlinNoise(200,200,4,Math.floor(Math.random()*0xffff),false,true,3|1|4|0);
}
}
}
class Particle{
public var xx:Number;
public var yy:Number;
public var zz:Number;
public var vx:Number;
public var vy:Number;
public var vz:Number;
public var ax:Number;
public var ay:Number;
public var az:Number;
}