Liquid150000 By Linked List
趣旨と違うことやってすみません
15万個パーティクル
// forked from clockmaker's Liquid110000 By Vector
// forked from munegon's forked from: forked from: forked from: forked from: Liquid10000
// forked from Saqoosha's forked from: forked from: forked from: Liquid10000
// forked from nutsu's forked from: forked from: Liquid10000
// forked from nutsu's forked from: Liquid10000
// forked from zin0086's Liquid10000
package {
/**
* 趣旨と違うことやってすみません
* 15万個パーティクル
*/
import flash.display.*;
import flash.geom.*;
import flash.events.*;
import flash.utils.*;
import flash.geom.*;
import net.hires.debug.Stats;
[SWF(width="465", height="465", backgroundColor="0x000000", frameRate="30")];
public class Liquid extends Sprite {
private const nums:uint = 150000;
private var bmpDat:BitmapData;
private var vectorDat:BitmapData;
private var randomSeed:uint = Math.floor( Math.random() * 0xFFFF );
private var bmp:Bitmap;
//private var vectorList:Vector.<VectorDat>;
private var rect:Rectangle;
private var cTra:ColorTransform;
private var vR:Number;
private var vG:Number;
private var timer:Timer;
private var vdroot:VectorDat;
private var vd:VectorDat;
public function Liquid() {
initialize();
}
private function initialize():void {
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.frameRate = 30;
stage.quality = StageQuality.LOW;
bmpDat= new BitmapData( 465, 465, false, 0x000000 );
vectorDat= new BitmapData( 28, 28, false, 0x000000 );
randomSeed= Math.floor( Math.random() * 0xFFFF );
vectorDat.perlinNoise( 14, 14, 3, randomSeed, false, true, 1|2|0|0 );
bmp= new Bitmap( bmpDat );
addChild( bmp );
rect = new Rectangle( 0, 0, 465, 465 )
cTra = new ColorTransform( .8, .8, .9, 1.0 );
vR = 0;
vG = 0;
var px:Number = Math.random()*465;
var py:Number = Math.random()*465;
vd = vdroot = new VectorDat(px, py);
//vectorList = new Vector.<VectorDat>(nums, true);
for (var i:uint = 1; i < nums; i++) {
px = Math.random()*465;
py = Math.random()*465;
vd = vd.next = new VectorDat(px, py);
//vectorList[i] = new VectorDat(px,py);
}
addEventListener( Event.ENTER_FRAME, loop );
timer = new Timer(500, 0);
timer.addEventListener(TimerEvent.TIMER, resetFunc);
timer.start();
addChild(new Stats);
}
private function loop( e:Event ):void {
bmpDat.lock();
bmpDat.colorTransform( rect, cTra );
//var len:uint = vectorList.length;
var col:Number;
var dots:VectorDat = this.vdroot;
for(;;)
{
//var dots:VectorDat = vectorList[i];
col = vectorDat.getPixel( dots.px>>4, dots.py>>4);
dots.ax += ( (col >> 16 & 0xff)-128 ) * .0005;
dots.ay += ( (col >> 8 & 0xff)-128 ) * .0005;
dots.vx += dots.ax;
dots.vy += dots.ay;
dots.px += dots.vx;
dots.py += dots.vy;
var _posX:Number = dots.px;
var _posY:Number = dots.py;
dots.ax *= .96;
dots.ay *= .96;
dots.vx *= .92;
dots.vy *= .92;
if (_posX > 465)
{
dots.px = 0;
}
else if (_posX < 0)
{
dots.px = 465;
}
if (_posY > 465)
{
dots.py = 0;
}
else if (_posY < 0)
{
dots.py = 465;
}
bmpDat.setPixel( dots.px, dots.py, 0xffffff );
dots = dots.next;
if (dots == null)
{
break;
}
}
bmpDat.unlock();
}
private var seed:Number = Math.floor( Math.random() * 0xFFFF );
private var offset:Array = [new Point(), new Point()];
private function resetFunc(e:Event):void{
vectorDat.perlinNoise( 14, 14, 3, seed, false, true, 1|2|0|0, false, offset );
offset[0].x += 1.5;
offset[1].y += 1.0;
var dots:VectorDat = this.vdroot;//vectorList[0];
vR += .001 * (dots.px-232)/465;
vG += .001 * (dots.py-232)/465;
( vR > .01 ) ? vR = .01:
( vR < -.01 ) ? vR = -.01:0;
( vG > .01 ) ? vG = .01:
( vG < -.01 ) ? vG = -.01:0;
cTra.redMultiplier += vR;
cTra.blueMultiplier += vG;
( cTra.redMultiplier > .9 ) ? cTra.redMultiplier = .9:
( cTra.redMultiplier < .5 ) ? cTra.redMultiplier = .5:cTra.redMultiplier;
( cTra.blueMultiplier > .9 ) ? cTra.blueMultiplier = .9:
( cTra.blueMultiplier < .5 ) ? cTra.blueMultiplier = .5:cTra.blueMultiplier;
}
}
}
class VectorDat {
public var vx:Number = 0;
public var vy:Number = 0;
public var ax:Number = 0;
public var ay:Number = 0;
public var px:Number;
public var py:Number;
public var next:VectorDat = null;
public var prev:VectorDat = null;
function VectorDat( px:Number, py:Number ) {
this.px = px;
this.py = py;
}
}