Pixel Fun Pixel Fun * @author civet * * BUG: when CLearType enable (2009-11-10) civet forked:0favorite:2lines:91license : All rights reserved modified : 2009-11-10 15:23:23 Embed Tweet /** * Pixel Fun * @author civet * * BUG: when CLearType enable (2009-11-10) */ package { import gs.*; import gs.easing.*; import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Shape; import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; import flash.events.TimerEvent; import flash.geom.Rectangle; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.text.TextFormat; import flash.utils.Timer; [SWF(frameRate='24', backgroundColor='0xffffff')] public class PixelFun extends Sprite { private static const DOT_SIZE:uint = 4; private static const DOT_SPACE:uint = 1; private var textfield:TextField; private var source:BitmapData; private var canvas:Sprite; private var list:Array; private var index:int = 0; public function PixelFun() { init(); } private function init():void { stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT; var str:String = "Hello World" + "|Ahhhhhhhhhhhhhhhh!" + "|The quick brown fox\njumps over the lazy dog."; list = str.split("|"); textfield = new TextField(); textfield.defaultTextFormat = new TextFormat("_sans", 12, 0); textfield.autoSize = TextFieldAutoSize.LEFT; source = new BitmapData(128, 32, false, 0xffffff);//range: 128 x 32 canvas = new Sprite(); addChild(canvas); onTick(); var t:Timer = new Timer(3000); t.addEventListener(TimerEvent.TIMER, onTick); t.start() } private function onTick(e:Event=null):void { clear(); textfield.text = list[ index++ ]; if(index > list.length-1) index = 0; source.draw(textfield); render(); } private function clear():void { var i:int = canvas.numChildren; while(i--) canvas.removeChildAt(i); source.fillRect(new Rectangle(0, 0, source.width, source.height), 0xffffff); } private function render():void { var w:uint = source.width; var h:uint = source.height; var i:uint; var j:uint; var color:uint; var dot:Shape; var SCALE:uint = DOT_SIZE + DOT_SPACE; for(i = 0; i < h; ++i) { for(j = 0; j < w; ++j) { color = source.getPixel(j, i); if(color == 0) { dot = createDot(0xfff << (j >> 2), DOT_SIZE); dot.x = int(Math.random()* textfield.width* SCALE); dot.y = int(Math.random()* textfield.height* SCALE); canvas.addChild(dot); //new GTween(dot, .5, {x: j* SCALE, y: i* SCALE}, {ease: Back.easeOut}); TweenLite.to(dot, .5, {x: j* SCALE, y: i* SCALE, ease:Back.easeOut}); } } } } private function createDot(color:uint, size:uint):Shape { var s:Shape = new Shape(); s.graphics.beginFill(color, 1); s.graphics.drawRect(0, 0, size, size); s.graphics.endFill(); return s; } } } Code Fullscreen Preview Fullscreen bradsedito Angelo getPixel color source size width height addEventListener split StageScaleMode.NO_SCALE start align TimerEvent.TIMER Rectangle Timer TextFormat text length uint String Array Math.random