color and wave(click and move)
Theme:
* Play with BitmapPatterBuilder.
* Purpose of this trial is to find the possibility of the dot pattern.
*
* by Takayuki Fukatsu aka fladdict
/**
* Copyright naoto5959 ( http://wonderfl.net/user/naoto5959 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/rasL
*/
// forked from checkmate's fladdict challenge for professionals
/**
* Theme:
* Play with BitmapPatterBuilder.
* Purpose of this trial is to find the possibility of the dot pattern.
*
* by Takayuki Fukatsu aka fladdict
**/
package {
import caurina.transitions.Tweener;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BlendMode;
import flash.display.GradientType;
import flash.display.Graphics;
import flash.display.Shape;
import flash.display.Sprite;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Matrix;
[SWF(width = "465", height = "465", backgroundColor = "0x000000", frameRate = "30")]
/**
* please click stage and move mouse.
* @author naoto koshikawa a.ka naoto5959
*/
public class Professional extends Sprite {
//----------------------------------------------------------------------
// properties
//----------------------------------------------------------------------
private var _colorPattern:Array = [0x33FFFFFF, 0x66FFFFFF, 0x99FFFFFF, 0xCCFFFFFF];
private var _methodPattern:Array = [sample1, sample2, sample3];
private var _gradation:Shape;
//----------------------------------------------------------------------
// method
//----------------------------------------------------------------------
/**
* constructor
*/
public function Professional() {
stage.scaleMode = StageScaleMode.NO_SCALE;
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
stage.addEventListener(MouseEvent.CLICK, clickHandler);
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
}
/**
* create gradation pattern
*/
private function createGradation():void
{
// create gradation
var graMatrix:Matrix = new Matrix();
graMatrix.createGradientBox(stage.stageWidth * 4, stage.stageHeight * 4, Math.PI/4, 0, 0);
_gradation = new Shape();
_gradation.graphics.beginGradientFill(
GradientType.LINEAR,
[0xFF0000, 0xFF9900, 0xFFFF00, 0x00FF00, 0x00FFFF, 0x0000FF],
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
[0, 51, 102, 153, 204, 255],
graMatrix
);
_gradation.graphics.drawRect(0, 0, stage.stageWidth * 4, stage.stageHeight * 4);
_gradation.blendMode = BlendMode.SCREEN;
_gradation.x = -stage.stageWidth * 1;
_gradation.y = -stage.stageHeight * 1;
addChild(_gradation);
}
//------------------------------
// pattern method
//------------------------------
/**
* sample1
* @return BitmapData
*/
private function sample1():BitmapData {
return BitmapPatternBuilder.build(
[
[0, 1, 2, 3],
[1, 2, 3, 0],
[2, 3, 0, 1],
[3, 0, 1, 2]
],
_colorPattern
);
}
/**
* sample2
* @return BitmapData
*/
private function sample2():BitmapData {
return BitmapPatternBuilder.build(
[
[0, 1, 2, 3],
[0, 1, 2, 3],
[1, 2, 3, 0],
[1, 2, 3, 0]
],
_colorPattern
);
}
/**
* sample3
* @return BitmapData
*/
private function sample3():BitmapData {
return BitmapPatternBuilder.build(
[
[0],
[1],
[2],
[3]
],
_colorPattern
);
}
//------------------------------
// event handler
//------------------------------
/**
* handler of Event.ENTER_FRAME
* @param event
*/
private function enterFrameHandler(event:Event = null):void
{
if (!_gradation) createGradation();
_colorPattern.push(_colorPattern.shift());
var pattern:BitmapData = _methodPattern[0]();
var g:Graphics = graphics;
g.clear();
g.beginBitmapFill(pattern);
g.drawRect(0,0,480,480);
g.endFill();
}
/**
* handler of MouseEvent.CLICK
* @param event
*/
private function clickHandler(event:MouseEvent):void
{
_methodPattern.push(_methodPattern.shift());
}
/**
* hanlder of MouseEvent.MOUSE_MOVE
* @param event
*/
private function mouseMoveHandler(event:MouseEvent = null):void
{
if (!_gradation) return;
Tweener.removeTweens(_gradation);
Tweener.addTween(_gradation,
{
x:(mouseX - stage.stageWidth)*2,
y:(mouseY - stage.stageHeight) * 2,
delay:0.3,
time:5,
transition:"easeOutExpo"
}
);
}
}
}
/**-----------------------------------------------------
* Use following BitmapPatternBuilder class
*
* DO NOT CHANGE any codes below this comment.
*
* -----------------------------------------------------
*/
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Graphics;
class BitmapPatternBuilder{
/**
* creates BitmapData filled with dot pattern.
* First parameter is 2d array that contains color index for each pixels;
* Second parameter contains color reference table.
*
* @parameter pattern:Array 2d array that contains color index for each pixel.
* @parameter colors:Array 1d array that contains color table.
* @returns BitmapData
*/
public static function build(pattern:Array, colors:Array):BitmapData{
var bitmapW:int = pattern[0].length;
var bitmapH:int = pattern.length;
var bmd:BitmapData = new BitmapData(bitmapW,bitmapH,true,0x000000);
for(var yy:int=0; yy<bitmapH; yy++){
for(var xx:int=0; xx<bitmapW; xx++){
var color:int = colors[pattern[yy][xx]];
bmd.setPixel32(xx, yy, color);
}
}
return bmd;
}
/**
* short cut function for Graphics.beginBitmapFill with pattern.
*/
public static function beginBitmapFill(pattern:Array, colors:Array, graphics:Graphics):void{
var bmd:BitmapData = build(pattern, colors);
graphics.beginBitmapFill(bmd);
bmd.dispose();
}
}