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
(forked from Murai's code)
* http://wonderfl.net/code/e9dee3eb5c7414aea0248344f204c1b397adc0ac
/**
* Copyright psyark ( http://wonderfl.net/user/psyark )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/4R1q
*/
// 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
**/
/**
* (forked from Murai's code)
* http://wonderfl.net/code/e9dee3eb5c7414aea0248344f204c1b397adc0ac
*/
package {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BlendMode;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.display.StageScaleMode;
import flash.events.*;
import flash.geom.Matrix;
[SWF(width=465,height=465,frameRate=60,backgroundColor=0x000000)]
public class ProfessionalAnim extends Sprite {
private var poses:Array = [
[
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,1,1,0,0,0,0],
[0,0,0,0,1,1,0,0,0,0],
[0,0,0,1,1,1,1,0,0,0],
[0,0,1,0,1,1,0,1,0,0],
[0,0,1,0,1,1,0,1,0,0],
[0,0,0,0,1,1,0,0,0,0],
[0,0,0,1,0,0,1,0,0,0],
[0,0,0,1,0,0,1,0,0,0],
[0,0,0,0,0,0,0,0,0,0]
],[
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,1,1,0,0,0,0],
[0,0,0,0,1,1,0,0,0,0],
[0,0,0,1,1,1,1,0,0,0],
[0,0,1,0,1,1,0,1,0,0],
[0,0,0,1,1,0,1,0,0,0],
[0,0,0,0,1,1,0,0,0,0],
[0,0,0,1,0,0,1,0,0,0],
[0,0,0,1,0,1,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0]
],[
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0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,0,0,1,0,0,0],
[0,0,0,1,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0]
],[
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,1,1,0,0,0,0],
[0,0,0,0,1,1,0,0,1,0],
[0,0,0,1,1,1,1,1,0,0],
[0,0,1,0,1,1,0,0,0,0],
[0,0,1,0,1,1,0,0,0,0],
[0,0,0,0,1,1,1,0,0,0],
[0,0,0,1,0,0,1,0,0,0],
[0,0,0,1,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0]
]
];
private var pattern:BitmapData;
private var pos:Number = 0;
private var spd:Number = 0;
private var film0:Film;
private var film3:Film;
public function ProfessionalAnim() {
stage.scaleMode = StageScaleMode.NO_SCALE;
var map:Array = [];
for each (var pose:Array in poses) {
for (var i:int=0; i<pose.length; i++) {
map[i] ||= [];
for (var j:int=0; j<5; j++) {
map[i] = map[i].concat(pose[i]);
}
}
}
pattern = BitmapPatternBuilder.build( map, [0xFFFFFFFF, 0xFF000000] );
film0 = new Film(pattern, 465, 465);
film3 = new Film(pattern, 465 / 8, 20);
film3.scaleX = film3.scaleY = 8;
film3.blendMode = BlendMode.MULTIPLY;
addChild(film0);
addChild(film3);
film3.y = 150;
addEventListener(Event.ENTER_FRAME, function(event:Event):void {
var spd2:Number = mouseX / 465 * 10 * 5;
spd += (spd2 - spd) * 0.04;
pos += spd * 2;
pos %= (pattern.width * 2);
film0.update(pos);
film3.update(pos);
film3.alpha = 1 - Math.abs((spd2 + 10) % 20 - 10);
});
}
}
}
import flash.display.Shape;
import flash.geom.Matrix;
class Film extends Shape {
private var pattern:BitmapData;
private var drawWidth:int;
private var drawHeight:int;
public function Film(pattern:BitmapData, drawWidth:int, drawHeight:int) {
this.pattern = pattern;
this.drawWidth = drawWidth;
this.drawHeight = drawHeight;
}
public function update(scroll:Number):void {
var mtx:Matrix = new Matrix();
mtx.a = mtx.d = 2;
mtx.tx = -scroll;
graphics.clear();
graphics.beginBitmapFill(pattern, mtx);
graphics.drawRect(0, 0, drawWidth, drawHeight);
graphics.endFill();
}
}
/**-----------------------------------------------------
* 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();
}
}