Pixel Text Block
build pixel text blocks by cubes
zoom fullscreen to get better performance
cubes are generated by Pixas
/**
* Copyright rison ( http://wonderfl.net/user/rison )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/libV
*/
package
{
import flash.display.*;
import flash.events.*;
import flash.geom.Matrix;
import flash.text.*;
import com.bit101.components.*;
import com.risonhuang.pixas.math.*;
import com.risonhuang.pixas.dimensions.*;
import com.risonhuang.pixas.objects.primitives.*;
import com.risonhuang.pixas.objects.*;
import com.risonhuang.pixas.colors.*;
/**
* @author max
* @see http://code.google.com/p/pixas/
*/
public class Main extends Sprite
{
private var bmd:BitmapData;
private var txt:TextField;
private var border:Boolean;
private var xDms:uint;
private var yDms:uint;
private var zDms:uint;
private var poFloor:PixelObject;
private var poTxt:PixelObject;
private var cube:Cube;
private var brick:Brick;
private var control:Sprite;
private var colorChooser:ColorChooser;
private var slide:HUISlider;
public function Main()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.quality = StageQuality.LOW;
//the value of cube dimensions in Pixas coordinate system
//!the xDms and yDms value must be even numbers
xDms = 12;
yDms = 12;
zDms = 14;
//whether show border
border = false;
//color
var control:Sprite = new Sprite();
colorChooser = new ColorChooser(control, 0, 0, ColorPattern.WINE_RED, __onColorChange);
colorChooser.usePopup = true;
slide = new HUISlider(control, 0, stage.stageHeight - control.y - 40, "size:", __onSlide);
slide.setSliderParams(6, 20, xDms);
slide.tick = 2;
slide.setSize(150, 20);
slide.labelPrecision = 0;
//text input area
var txt_mc:Sprite = new Sprite();
var lable:Label = new Label(txt_mc, 0, 0, "Input Something:");
var txtFmt:TextFormat = new TextFormat();
txtFmt.font = "Verdana";
txtFmt.size = 12;
txtFmt.leading = 2;
txt = new TextField();
txt.antiAliasType = AntiAliasType.NORMAL;
txt.defaultTextFormat = txtFmt;
txt.type = TextFieldType.INPUT;
txt.text = "eo.iMessage";
txt.border = true;
txt.borderColor = 0xBBBBBB;
txt.background = true;
txt.backgroundColor = 0xFFFFFF;
txt.autoSize = TextFieldAutoSize.LEFT;
txt.addEventListener(Event.CHANGE, __onTxtChange);
txt.addEventListener(FocusEvent.FOCUS_IN, __onTxtFocusIn);
//cube primitive
var cubeDms:CubeDms = new CubeDms(xDms,yDms,zDms);
var cubeColor:CubeColor = CubeColor.getByHorizontalColor(ColorPattern.WINE_RED);
cube = new Cube(cubeDms, cubeColor, border);
//brick primitive
var brickDms:BrickDms = new BrickDms(xDms,yDms);
var sideColor:SideColor = new SideColor(0xBBBBBB);
brick = new Brick(brickDms, sideColor);
//out container
var po:PixelObject = new PixelObject();
//floor container
poFloor = new PixelObject();
//text display container
poTxt = new PixelObject();
//control
control.x = control.y = 10;
addChild(control);
//pixel obj
po.x = 110;
po.y = 50;
po.addChild(poFloor);
po.addChild(poTxt);
addChild(po);
//txt
txt_mc.x = 90;
txt_mc.y = 10;
txt.x = lable.width;
txt.y = -2;
txt_mc.addChild(txt);
addChild(txt_mc);
//init rendering
__onTxtChange(null);
}
private function __onColorChange(e:Event = null):void
{
//reset cube primitive
var cubeDms:CubeDms = new CubeDms(xDms,yDms,zDms);
var cubeColor:CubeColor = CubeColor.getByHorizontalColor(colorChooser.value);
cube = new Cube(cubeDms, cubeColor, border);
__onTxtChange(null);
}
private function __onTxtFocusIn(e:FocusEvent):void
{
txt.text = "";
}
private function __onSlide(e:Event):void
{
xDms = yDms = slide.value;
zDms = xDms +2;
//cube primitive
var cubeDms:CubeDms = new CubeDms(xDms,yDms,zDms);
var cubeColor:CubeColor = CubeColor.getByHorizontalColor(colorChooser.value);
cube = new Cube(cubeDms, cubeColor, border);
//brick primitive
var brickDms:BrickDms = new BrickDms(xDms,yDms);
var sideColor:SideColor = new SideColor(0xBBBBBB);
brick = new Brick(brickDms, sideColor);
__onTxtChange(null);
}
private function __onTxtChange(e:Event):void
{
var txtWidth:uint = txt.textWidth + 1;
var txtHeight:uint = txt.textHeight;
try
{
poFloor.removeAllChildren();
poTxt.removeAllChildren();
bmd.dispose();
}
catch (e:Error){}
try
{
var mtx:Matrix = new Matrix(1, 0, 0, 1, -1, -2);
bmd = new BitmapData(txtWidth,txtHeight);
bmd.draw(txt,mtx);
/*
//test bm
var bm:Bitmap = new Bitmap(bmd);
addChild(bm)
*/
}
catch (e:Error) { return; }
for (var p_y:uint=0; p_y<txtHeight - 1; p_y++)
{
for (var p_x:uint =0; p_x<txtWidth; p_x++)
{
var int3d:Coord3D = new Coord3D((xDms - 2) * p_x, (yDms - 2) * p_y, 0);
//each brick PixelObject
var po_brick:PixelObject = new PixelObject(brick,int3d);
poFloor.addChild(po_brick);
//each text display PixelObject
if (bmd.getPixel(p_x,p_y) < 0x999999)
{
var po_cube:PixelObject = new PixelObject(cube,int3d);
poTxt.addChild(po_cube);
}
}
}
}
}
}