forked from: 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
/**
* Copyright tocy ( http://wonderfl.net/user/tocy )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/it0m
*/
// 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 flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.events.Event;
import flash.filters.BlurFilter;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.display.StageScaleMode;
public class Professional extends Sprite {
public function Professional() {
stage.scaleMode = StageScaleMode.NO_SCALE;
//generate bitmap pattern.
var size:int = 24;
var rets:Array = new Array();
rets.push( getTextPattern("心",size-4) );
rets.push( getTextPattern("技",size-4) );
rets.push( getTextPattern("体",size-4) );
var count:int = 0;
var g:Graphics = graphics;
var frames:int = 0;
addEventListener( Event.ENTER_FRAME, function(ev:Event):void {
frames++;
g.clear();
if ( frames>40 ) {
frames = 0;
count++;
}
var strength:Number = frames/4;
filters = [new BlurFilter(strength,strength)];
var ret:Array = rets[count];
if ( count>rets.length-1 ) count=0;
var pattern:BitmapData = makePattern(ret);
var block:Number = 480/size;
for ( var i:int=0; i<ret.length; i++ ) {
for ( var j:int=0; j<ret[0].length; j++ ) {
if ( ret[i][j]>0 ) {
g.beginBitmapFill(pattern);
g.drawCircle(j*block,i*block,block);
g.endFill();
} else {
}
}
}
});
}
public function makePattern(pat:Array):BitmapData
{
return BitmapPatternBuilder.build(
pat,
[0xFFFFFFFF, 0x77FF9999, 0x77FF9999,
0x55000000, 0x33000000, 0x11000000,
0xFF000000]
);
}
public function getTextPattern(txt:String,size:int):Array
{
var tf:TextField = new TextField();
var format:TextFormat = new TextFormat();
format.size = size;
tf.defaultTextFormat = format;
tf.textColor = 0x000000;
tf.text = txt;
tf.autoSize = TextFieldAutoSize.LEFT;
addChild(tf);
var tw:Number = tf.width;
var th:Number = tf.height;
var bdata:BitmapData = new BitmapData(tw,th);
bdata.draw(tf);
tf.visible = false;
var ret:Array = new Array();
for ( var row:int=0; row<th; row++ ) {
ret[row] = new Array();
}
for ( var i:int=0; i<th; i++ ) {
for ( var j:int=0; j<tw; j++ ) {
var flag:Boolean = bdata.getPixel(j,i)==0xFFFFFF;
if ( flag ) {
ret[i][j] = 0;
} else {
ret[i][j] = 1;
if ( j>0 && j<tw-1 && i>0 && i<th-1 ) {
var i1:Number = (i==0)? 0 : i-1;
var i2:Number = i;
var i3:Number = (i<th-2)? i+1 : i;
var j1:Number = (j==0)? 0 : j-1;
var j2:Number = j;
var j3:Number = (j<tw-2) ? j+1 : 0;
ret[i1][j1] += 1;
ret[i1][j2] += 1;
ret[i1][j3] += 1;
ret[i2][j1] += 1;
ret[i2][j2] = 1;
ret[i2][j3] += 1;
ret[i3][j1] += 1;
ret[i3][j2] += 1;
ret[i3][j3] += 1;
}
}
}
}
return ret;
}
}
}
/**-----------------------------------------------------
* 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();
}
}