按r可以改变流动方式
源代码:
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.filters.*;
import flash.geom.Point;
const sx:int=stage.stageWidth;
const sy:int=stage.stageHeight;
var tempX:Number,tempY:Number;
var tempX2:Number,tempY2:Number;
var partices:int=6000;
var parPos:Point=new Point(sx/2,sy);
var r:int=40;
var gfx:BitmapData=new BitmapData(sx,sy,false,0x0);
var cover:BitmapData=new BitmapData(sx,sy,true,0x01000000);
addChild(new Bitmap(gfx));
gfx.perlinNoise(Math.random()*100,Math.random()*100,Math.random()*8,Math.random()*8,false,false);
var filter:ColorMatrixFilter=new ColorMatrixFilter([1,0,0,0,-1.8,
0,1,0,0,-1.9,
0,0,1,0,-0.1,
0,0,0,1,0]);
var noiseList:Array=new Array();
for(var i:int=0;i<sx;i++)
{
noiseList[i]=[];
for(var j:int=0;j<sy;j++)
noiseList[i][j]={x:(gfx.getPixel(i,j)-gfx.getPixel(i+1,j))/1000000,y:(gfx.getPixel(i,j)-gfx.getPixel(i,j+1))/1000000};
}
var particeList:Array=new Array();
for(i=0;i<partices;i++)
{
tempX=Math.cos(Math.random()*Math.PI*2)*Math.random()*r+parPos.x;
tempY=Math.sin(Math.random()*Math.PI*2)*Math.random()*r+parPos.y;
particeList[i]={x:tempX,y:tempY,vx:parPos.x-tempX,vy:parPos.y-tempY};
}
gfx.fillRect(gfx.rect,0x000000);
function main():void
{
for(i=0;i<partices;i++)
{
tempX2=Math.floor(particeList[i].x);
tempY2=Math.floor(particeList[i].y);
if(tempX2<sx&&tempY2<sy){
particeList[i].x+=noiseList[tempX2][tempY2].x;
particeList[i].y+=noiseList[tempX2][tempY2].y;
particeList[i].y-=0.4+Math.random()*0.9;
(Math.round(Math.random()*8)<=4) ? particeList[i].x+=Math.random()*0.8 : particeList[i].x-=Math.random()*0.8;
}
if(particeList[i].x>sx||particeList[i].y>sy||particeList[i].x<0||particeList[i].y<0){
particeList[i].x=Math.cos(Math.random()*Math.PI*2)*Math.random()*r+parPos.x;
particeList[i].y=Math.sin(Math.random()*Math.PI*2)*Math.random()*r+parPos.y;
}
gfx.setPixel(particeList[i].x,particeList[i].y,0xE48C0A);
}
gfx.applyFilter(gfx,gfx.rect,new Point(0,0),filter);
setTimeout(main,1);
}
function reportKeyDown(event:KeyboardEvent):void{
if(String.fromCharCode(event.charCode)=="r")
{
gfx.perlinNoise(Math.random()*100,Math.random()*100,Math.random()*8,Math.random()*8,false,false);
for(var i:int=0;i<sx;i++)
{
noiseList[i]=[];
for(var j:int=0;j<sy;j++)
noiseList[i][j]={x:(gfx.getPixel(i,j)-gfx.getPixel(i+1,j))/1000000,y:(gfx.getPixel(i,j)-gfx.getPixel(i,j+1))/1000000};
}
gfx.fillRect(gfx.rect,0x000000);
}
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, reportKeyDown);
main();
回复Comments
作者:
{commentrecontent}