WaterColor Flow
WaterColor Flow
civet
dreamana.com
2009-04-28
/**
* WaterColor Flow
* civet
* dreamana.com
* 2009-04-28
*/
package {
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BitmapDataChannel;
import flash.events.*;
import flash.geom.Point;
import flash.utils.Timer;
[SWF(frameRate='24', backgroundColor='0xffffff')]
public class WaterColorFlow extends Sprite {
private var bmd:BitmapData;
private var seed:int;
private var channels:uint;
private var pt:Point
private var offset:Array;
private var timer:Timer;
public function WaterColorFlow() {
bmd = new BitmapData(640, 480, true, 0x00000000);
addChild( new Bitmap(bmd) );
seed = int(Math.random() * 10);
channels = BitmapDataChannel.ALPHA | BitmapDataChannel.RED | BitmapDataChannel.GREEN | BitmapDataChannel.BLUE;
pt = new Point();
offset = [pt, pt];
timer = new Timer(60);
timer.addEventListener(TimerEvent.TIMER, loop);
timer.start();
stage.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
}
private function onDown(event:Event):void {
if(timer.running) timer.stop();
else timer.start();
}
private function loop(e:Event):void {
bmd.lock();
bmd.perlinNoise(320, 240, 2, seed, false, true, channels, false, offset);
bmd.unlock();
pt.x += (mouseX - 320) >> 2; //offsetX;
pt.y += (mouseY - 240) >> 2; //offsetY;
}
}
}