forked from: forked from: forked from: Bitmapdata.noise
コマンドのループby俺俺コマンド
// forked from northprint's forked from: forked from: Bitmapdata.noise
// forked from northprint's forked from: Bitmapdata.noise
// forked from northprint's Bitmapdata.noise
//コマンドのループby俺俺コマンド
// write as3 code here..
package {
import flash.display.*;
import flash.events.*;
import jp.progression.commands.*;
import jp.progression.events.*;
public class NoiseTest extends MovieClip {
private var _bitmapdata:BitmapData;
private var _bitmap:Bitmap;
private var _loop:LoopCommand;
private var _noiseMode:int = 0;
public function NoiseTest() {
_bitmapdata = new BitmapData( stage.stageWidth, stage.stageHeight, true );
_bitmap = new Bitmap( _bitmapdata );
addChild( _bitmap );
addEventListener( Event.ENTER_FRAME, _enterFrame );
_loop = new LoopCommand(
new SerialList( null,
function():void { _noiseMode = ++_noiseMode % 3; },
new Wait( 3000 )
),
function():Boolean { return false; }
);
_loop.execute();
}
private function _enterFrame( e:Event ):void {
var low:Number = Math.random() * 64;
var high:Number = Math.random() * 128 + 128;
switch ( _noiseMode ) {
case 0 : { _bitmapdata.noise( 1, low, high, 1 | 1 | 1, false ); break; }
case 1 : { _bitmapdata.noise( 1, low, high, 4 | 4 | 4, false ); break; }
case 2 : { _bitmapdata.noise( 1, low, high, 2 | 2 | 1, false ); break; }
}
}
}
}
import jp.progression.commands.*;
import jp.progression.core.commands.Command;
import jp.progression.events.*;
class LoopCommand extends Command {
private var _command:Command;
private var _condition:Function;
public function LoopCommand( command:Command, condition:Function, initObject:Object = null ) {
super( _execute, _interrupt, initObject );
_command = command;
_condition = condition;
timeOut = 0;
}
private function _execute():void{
if ( _condition.apply( this ) ) {
executeComplete();
}
_command.addEventListener( CommandEvent.COMMAND_COMPLETE, _commandComplete );
_command.execute();
}
private function _commandComplete( e:CommandEvent ):void {
_command.removeEventListener( CommandEvent.COMMAND_COMPLETE, _commandComplete );
_execute();
}
private function _interrupt():void {
if ( _command ) {
_command.removeEventListener( CommandEvent.COMMAND_COMPLETE, _commandComplete );
_command = null;
}
interruptComplete();
}
public override function clone():Command{
return new LoopCommand( _command, _condition, this );
}
}