/**
* Copyright hemingway ( http://wonderfl.net/user/hemingway )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/8Fps
*/
package
{
import flash.display.*;
import flash.events.*;
[SWF(frameRate=60, width=1024, height=768)]
public class Main extends Sprite
{
private var canvasBorder :Sprite;
private var canvasBackground :Sprite;
public function Main()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
canvasBorder = new Sprite();
canvasBackground = new Sprite();
addEventListener(Event.ADDED_TO_STAGE, addedToStage);
}
public function addedToStage($e:*) :void
{
removeEventListener(Event.ADDED_TO_STAGE, addedToStage);
stage.addChild(canvasBackground); //fill
Buffer.initContext(stage); //custom App
stage.addChild(canvasBorder); //border
init();
}
public function init() :void
{
canvasBorder.graphics.clear();
canvasBorder.graphics.lineStyle(2);
canvasBorder.graphics.drawRect(1, 1, 1022, 766);
canvasBackground.graphics.beginFill(0x888888);
canvasBackground.graphics.drawRect(0, 0, 1024, 768);
canvasBackground.graphics.endFill();
}
}
}
import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.text.*;
class Buffer
{
public static var TITLE :Output;
public static var CANVAS :Stage;
public static var OUTPUT :Output;
public static var GRID_SCALE :int;
public static var GRID_SIZE :Point;
public static var GRID_ARRAY :Array;
public static var COLOR_ARRAY :Array;
public static var GRID_MARGIN :Point;
public static var GUIDE_MARGIN :Point;
public static var NODE_PROGRESS :Array;
public static var SELECTED_COLUMN :int;
public static var GRID_GUIDE :GridGuide;
public static var GRID_HIGHLIGHT :Boolean;
public static var NODE_GLOBAL_STATUS :int;
public static function initContext($canvas:Stage) :void
{
var $guideX :int;
var $guideY :int;
TITLE = new Output("");
OUTPUT = new Output("Color Depth v5.9");
CANVAS = $canvas;
GRID_SIZE = new Point(11, 12);
GRID_SCALE = 48;
GRID_MARGIN = new Point(3, 2);
GUIDE_MARGIN = new Point(2, 2);
GRID_HIGHLIGHT = false;
NODE_GLOBAL_STATUS = 0;
NODE_PROGRESS = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
$guideX = (GRID_SCALE*GUIDE_MARGIN.x);
$guideY = (GRID_SCALE*GUIDE_MARGIN.y);
CANVAS.addChild(new GridGuide($guideX, $guideY));
CANVAS.addChild(new ProgressPanel(720, 96));
CANVAS.addChild(OUTPUT);
initGrid();
}
public static function initGrid() :void
{
var $index :Point = new Point(1, 1);
var $gridMin :Point = new Point((GRID_MARGIN.x - $index.x), (GRID_MARGIN.y - $index.y));
GRID_ARRAY = [];
COLOR_ARRAY = [];
for (var $x:int = $index.x; $x <= GRID_SIZE.x; $x++)
{
GRID_ARRAY[$x] = [];
COLOR_ARRAY[$x] = [];
for (var $y:int = $index.y; $y <= GRID_SIZE.y; $y++)
{
GRID_ARRAY[$x][$y] = new GridNode((($gridMin.x+$x)*GRID_SCALE), (($gridMin.y+$y)*GRID_SCALE), GRID_SCALE);
COLOR_ARRAY[$x][$y] = 0xFFFFFF;
CANVAS.addChild(GRID_ARRAY[$x][$y]);
}
}
GRID_ARRAY[1][1].color = COLOR_ARRAY[1][1] = 0xFF9999;
GRID_ARRAY[1][2].color = COLOR_ARRAY[1][2] = 0xFF8080;
GRID_ARRAY[1][3].color = COLOR_ARRAY[1][3] = 0xFF6666;
GRID_ARRAY[1][4].color = COLOR_ARRAY[1][4] = 0xFF4D4D;
GRID_ARRAY[1][5].color = COLOR_ARRAY[1][5] = 0xFF3333;
GRID_ARRAY[1][6].color = COLOR_ARRAY[1][6] = 0xFF1A1A;
GRID_ARRAY[1][7].color = COLOR_ARRAY[1][7] = 0xFF0000;
GRID_ARRAY[1][8].color = COLOR_ARRAY[1][8] = 0xE60000;
GRID_ARRAY[1][9].color = COLOR_ARRAY[1][9] = 0xCC0000;
GRID_ARRAY[1][10].color = COLOR_ARRAY[1][10] = 0xB30000;
GRID_ARRAY[1][11].color = COLOR_ARRAY[1][11] = 0x990000;
GRID_ARRAY[1][12].color = COLOR_ARRAY[1][12] = 0x800000;
GRID_ARRAY[2][1].color = COLOR_ARRAY[2][1] = 0xFFCE99;
GRID_ARRAY[2][2].color = COLOR_ARRAY[2][2] = 0xFFC180;
GRID_ARRAY[2][3].color = COLOR_ARRAY[2][3] = 0xFFB566;
GRID_ARRAY[2][4].color = COLOR_ARRAY[2][4] = 0xFFA94D;
GRID_ARRAY[2][5].color = COLOR_ARRAY[2][5] = 0xFF9C33;
GRID_ARRAY[2][6].color = COLOR_ARRAY[2][6] = 0xFF901A;
GRID_ARRAY[2][7].color = COLOR_ARRAY[2][7] = 0xFF8400;
GRID_ARRAY[2][8].color = COLOR_ARRAY[2][8] = 0xE67700;
GRID_ARRAY[2][9].color = COLOR_ARRAY[2][9] = 0xCC6900;
GRID_ARRAY[2][10].color = COLOR_ARRAY[2][10] = 0xB35C00;
GRID_ARRAY[2][11].color = COLOR_ARRAY[2][11] = 0x994F00;
GRID_ARRAY[2][12].color = COLOR_ARRAY[2][12] = 0x804200;
GRID_ARRAY[3][1].color = COLOR_ARRAY[3][1] = 0xFFFF99;
GRID_ARRAY[3][2].color = COLOR_ARRAY[3][2] = 0xFFFF80;
GRID_ARRAY[3][3].color = COLOR_ARRAY[3][3] = 0xFFFF66;
GRID_ARRAY[3][4].color = COLOR_ARRAY[3][4] = 0xFFFF4D;
GRID_ARRAY[3][5].color = COLOR_ARRAY[3][5] = 0xFFFF33;
GRID_ARRAY[3][6].color = COLOR_ARRAY[3][6] = 0xFFFF1A;
GRID_ARRAY[3][7].color = COLOR_ARRAY[3][7] = 0xFFFF00;
GRID_ARRAY[3][8].color = COLOR_ARRAY[3][8] = 0xE6E600;
GRID_ARRAY[3][9].color = COLOR_ARRAY[3][9] = 0xCCCC00;
GRID_ARRAY[3][10].color = COLOR_ARRAY[3][10] = 0xB3B300;
GRID_ARRAY[3][11].color = COLOR_ARRAY[3][11] = 0x999900;
GRID_ARRAY[3][12].color = COLOR_ARRAY[3][12] = 0x808000;
GRID_ARRAY[4][1].color = COLOR_ARRAY[4][1] = 0xCFFF99;
GRID_ARRAY[4][2].color = COLOR_ARRAY[4][2] = 0xC3FF80;
GRID_ARRAY[4][3].color = COLOR_ARRAY[4][3] = 0xB8FF66;
GRID_ARRAY[4][4].color = COLOR_ARRAY[4][4] = 0xACFF4D;
GRID_ARRAY[4][5].color = COLOR_ARRAY[4][5] = 0xA0FF33;
GRID_ARRAY[4][6].color = COLOR_ARRAY[4][6] = 0x94FF1A;
GRID_ARRAY[4][7].color = COLOR_ARRAY[4][7] = 0x88FF00;
GRID_ARRAY[4][8].color = COLOR_ARRAY[4][8] = 0x7AE600;
GRID_ARRAY[4][9].color = COLOR_ARRAY[4][9] = 0x6DCC00;
GRID_ARRAY[4][10].color = COLOR_ARRAY[4][10] = 0x5FB300;
GRID_ARRAY[4][11].color = COLOR_ARRAY[4][11] = 0x529900;
GRID_ARRAY[4][12].color = COLOR_ARRAY[4][12] = 0x448000;
GRID_ARRAY[5][1].color = COLOR_ARRAY[5][1] = 0x99FF99;
GRID_ARRAY[5][2].color = COLOR_ARRAY[5][2] = 0x80FF80;
GRID_ARRAY[5][3].color = COLOR_ARRAY[5][3] = 0x66FF66;
GRID_ARRAY[5][4].color = COLOR_ARRAY[5][4] = 0x4DFF4D;
GRID_ARRAY[5][5].color = COLOR_ARRAY[5][5] = 0x33FF33;
GRID_ARRAY[5][6].color = COLOR_ARRAY[5][6] = 0x1AFF1A;
GRID_ARRAY[5][7].color = COLOR_ARRAY[5][7] = 0x00FF00;
GRID_ARRAY[5][8].color = COLOR_ARRAY[5][8] = 0x00E600;
GRID_ARRAY[5][9].color = COLOR_ARRAY[5][9] = 0x00CC00;
GRID_ARRAY[5][10].color = COLOR_ARRAY[5][10] = 0x00B300;
GRID_ARRAY[5][11].color = COLOR_ARRAY[5][11] = 0x009900;
GRID_ARRAY[5][12].color = COLOR_ARRAY[5][12] = 0x008000;
GRID_ARRAY[6][1].color = COLOR_ARRAY[6][1] = 0x99FFCF;
GRID_ARRAY[6][2].color = COLOR_ARRAY[6][2] = 0x80FFC3;
GRID_ARRAY[6][3].color = COLOR_ARRAY[6][3] = 0x66FFB8;
GRID_ARRAY[6][4].color = COLOR_ARRAY[6][4] = 0x4DFFAC;
GRID_ARRAY[6][5].color = COLOR_ARRAY[6][5] = 0x33FFA0;
GRID_ARRAY[6][6].color = COLOR_ARRAY[6][6] = 0x1AFF94;
GRID_ARRAY[6][7].color = COLOR_ARRAY[6][7] = 0x00FF88;
GRID_ARRAY[6][8].color = COLOR_ARRAY[6][8] = 0x00E67A;
GRID_ARRAY[6][9].color = COLOR_ARRAY[6][9] = 0x00CC6D;
GRID_ARRAY[6][10].color = COLOR_ARRAY[6][10] = 0x00B35F;
GRID_ARRAY[6][11].color = COLOR_ARRAY[6][11] = 0x009952;
GRID_ARRAY[6][12].color = COLOR_ARRAY[6][12] = 0x008044;
GRID_ARRAY[7][1].color = COLOR_ARRAY[7][1] = 0x99FFFF;
GRID_ARRAY[7][2].color = COLOR_ARRAY[7][2] = 0x80FFFF;
GRID_ARRAY[7][3].color = COLOR_ARRAY[7][3] = 0x66FFFF;
GRID_ARRAY[7][4].color = COLOR_ARRAY[7][4] = 0x4DFFFF;
GRID_ARRAY[7][5].color = COLOR_ARRAY[7][5] = 0x33FFFF;
GRID_ARRAY[7][6].color = COLOR_ARRAY[7][6] = 0x1AFFFF;
GRID_ARRAY[7][7].color = COLOR_ARRAY[7][7] = 0x00FFFF;
GRID_ARRAY[7][8].color = COLOR_ARRAY[7][8] = 0x00E6E6;
GRID_ARRAY[7][9].color = COLOR_ARRAY[7][9] = 0x00CCCC;
GRID_ARRAY[7][10].color = COLOR_ARRAY[7][10] = 0x00B3B3;
GRID_ARRAY[7][11].color = COLOR_ARRAY[7][11] = 0x009999;
GRID_ARRAY[7][12].color = COLOR_ARRAY[7][12] = 0x008080;
GRID_ARRAY[8][1].color = COLOR_ARRAY[8][1] = 0x99CFFF;
GRID_ARRAY[8][2].color = COLOR_ARRAY[8][2] = 0x80C3FF;
GRID_ARRAY[8][3].color = COLOR_ARRAY[8][3] = 0x66B8FF;
GRID_ARRAY[8][4].color = COLOR_ARRAY[8][4] = 0x4DACFF;
GRID_ARRAY[8][5].color = COLOR_ARRAY[8][5] = 0x33A0FF;
GRID_ARRAY[8][6].color = COLOR_ARRAY[8][6] = 0x1A94FF;
GRID_ARRAY[8][7].color = COLOR_ARRAY[8][7] = 0x0088FF;
GRID_ARRAY[8][8].color = COLOR_ARRAY[8][8] = 0x007AE6;
GRID_ARRAY[8][9].color = COLOR_ARRAY[8][9] = 0x006DCC;
GRID_ARRAY[8][10].color = COLOR_ARRAY[8][10] = 0x005FB3;
GRID_ARRAY[8][11].color = COLOR_ARRAY[8][11] = 0x005299;
GRID_ARRAY[8][12].color = COLOR_ARRAY[8][12] = 0x004480;
GRID_ARRAY[9][1].color = COLOR_ARRAY[9][1] = 0x9999FF;
GRID_ARRAY[9][2].color = COLOR_ARRAY[9][2] = 0x8080FF;
GRID_ARRAY[9][3].color = COLOR_ARRAY[9][3] = 0x6666FF;
GRID_ARRAY[9][4].color = COLOR_ARRAY[9][4] = 0x4D4DFF;
GRID_ARRAY[9][5].color = COLOR_ARRAY[9][5] = 0x3333FF;
GRID_ARRAY[9][6].color = COLOR_ARRAY[9][6] = 0x1A1AFF;
GRID_ARRAY[9][7].color = COLOR_ARRAY[9][7] = 0x0000FF;
GRID_ARRAY[9][8].color = COLOR_ARRAY[9][8] = 0x0000E6;
GRID_ARRAY[9][9].color = COLOR_ARRAY[9][9] = 0x0000CC;
GRID_ARRAY[9][10].color = COLOR_ARRAY[9][10] = 0x0000B3;
GRID_ARRAY[9][11].color = COLOR_ARRAY[9][11] = 0x000099;
GRID_ARRAY[9][12].color = COLOR_ARRAY[9][12] = 0x000080;
GRID_ARRAY[10][1].color = COLOR_ARRAY[10][1] = 0xCF99FF;
GRID_ARRAY[10][2].color = COLOR_ARRAY[10][2] = 0xC380FF;
GRID_ARRAY[10][3].color = COLOR_ARRAY[10][3] = 0xB866FF;
GRID_ARRAY[10][4].color = COLOR_ARRAY[10][4] = 0xAC4DFF;
GRID_ARRAY[10][5].color = COLOR_ARRAY[10][5] = 0xA033FF;
GRID_ARRAY[10][6].color = COLOR_ARRAY[10][6] = 0x941AFF;
GRID_ARRAY[10][7].color = COLOR_ARRAY[10][7] = 0x8800FF;
GRID_ARRAY[10][8].color = COLOR_ARRAY[10][8] = 0x7A00E6;
GRID_ARRAY[10][9].color = COLOR_ARRAY[10][9] = 0x6D00CC;
GRID_ARRAY[10][10].color = COLOR_ARRAY[10][10] = 0x5F00B3;
GRID_ARRAY[10][11].color = COLOR_ARRAY[10][11] = 0x520099;
GRID_ARRAY[10][12].color = COLOR_ARRAY[10][12] = 0x440080;
GRID_ARRAY[11][1].color = COLOR_ARRAY[11][1] = 0xFF99FF;
GRID_ARRAY[11][2].color = COLOR_ARRAY[11][2] = 0xFF80FF;
GRID_ARRAY[11][3].color = COLOR_ARRAY[11][3] = 0xFF66FF;
GRID_ARRAY[11][4].color = COLOR_ARRAY[11][4] = 0xFF4DFF;
GRID_ARRAY[11][5].color = COLOR_ARRAY[11][5] = 0xFF33FF;
GRID_ARRAY[11][6].color = COLOR_ARRAY[11][6] = 0xFF1AFF;
GRID_ARRAY[11][7].color = COLOR_ARRAY[11][7] = 0xFF00FF;
GRID_ARRAY[11][8].color = COLOR_ARRAY[11][8] = 0xE600E6;
GRID_ARRAY[11][9].color = COLOR_ARRAY[11][9] = 0xCC00CC;
GRID_ARRAY[11][10].color = COLOR_ARRAY[11][10] = 0xB300B3;
GRID_ARRAY[11][11].color = COLOR_ARRAY[11][11] = 0x990099;
GRID_ARRAY[11][12].color = COLOR_ARRAY[11][12] = 0x800080;
GRID_HIGHLIGHT = true;
}
public static function bringToFront($:DisplayObject) :void
{
CANVAS.setChildIndex($, (CANVAS.numChildren-2)); //gridHighlight is top-most DisplayObject, so subtract '2' instead of '1'
CANVAS.setChildIndex($, (CANVAS.numChildren-3));
}
public static function identifyColumn($:DisplayObject) :int
{
var $temp :int = -1;
var $index :Point = new Point(1, 1);
for (var $x:int = $index.x; $x <= GRID_SIZE.x; $x++)
{
for (var $y:int = $index.y; $y <= GRID_SIZE.y; $y++)
{
if ($ == GRID_ARRAY[$x][$y])
{
$temp = $x;
break;
}
}
}
return $temp;
}
public static function checkNodeStatus() :int
{
var $temp :int = 0;
var $return :Boolean;
for (var $y:int = 1; $y < GRID_SIZE.y; $y++)
{
(GRID_ARRAY[SELECTED_COLUMN][$y].status == 2) ? null : $temp++;
}
return($temp);
}
public static function resetNodes() :void
{
CANVAS.removeEventListener(Event.ENTER_FRAME, nodeTransitionBuffer)
for (var $x:int = 1; $x <= GRID_SIZE.x; $x++)
{
for (var $y:int = 1; $y <= GRID_SIZE.y; $y++)
{
if (NODE_PROGRESS[$x-1] != 1)
{
if ($x != SELECTED_COLUMN)
{
NODE_PROGRESS[SELECTED_COLUMN-1] = 1;
GRID_ARRAY[$x][$y].mouseEnabled = GRID_ARRAY[$x][$y].visible = true;
GRID_GUIDE.columnLock = 0;
}else{
//GRID_ARRAY[$x][$y].mouseEnabled = false;
}
}
}
}
}
public static function scatterNodes($:DisplayObject) :void
{
var $index :Point = new Point(1, 1);
var $column :int = identifyColumn($);
SELECTED_COLUMN = $column;
for (var $x:int = $index.x; $x <= GRID_SIZE.x; $x++)
{
for (var $y:int = $index.y; $y <= GRID_SIZE.y; $y++)
{
//GRID_ARRAY[$x][$y].mouseEnabled = false;
if ($x != $column)
{
GRID_ARRAY[$x][$y].visible = false;
GRID_GUIDE.columnLock = $column;
}
}
}
CANVAS.addEventListener(Event.ENTER_FRAME, nodeTransitionBuffer);
}
/*not needed due to individual node's handling their own normalization*/
//public static function normalizeNodes($:DisplayObject) :void
//{;}
public static function nodeTransitionBuffer($e:Event) :void
{
for (var $x:int = 1; $x <= GRID_SIZE.x; $x++)
{
for (var $y:int = 1; $y <= GRID_SIZE.y; $y++)
{
if ($x == SELECTED_COLUMN)
{
GRID_ARRAY[$x][$y].statusTransition();
}
}
}
}
}
class GridGuide extends Sprite
{
private var gridHighlight :Sprite;
protected var _index :int;
protected var _columnLock :int;
public function GridGuide($x:Number, $y:Number)
{
addEventListener(Event.ADDED_TO_STAGE, addedToStage);
x = $x;
y = $y;
_index = -20;
_columnLock = 0;
gridHighlight = new Sprite();
gridHighlight.x = x;
gridHighlight.y = y;
Buffer.GRID_GUIDE = this;
}
public function addedToStage($e:*) :void
{
removeEventListener(Event.ADDED_TO_STAGE, addedToStage);
init();
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
public function init() :void
{
var $gridScale :* = Buffer.GRID_SCALE;
var $gridSize :* = Buffer.GRID_SIZE.y;
graphics.clear();
graphics.lineStyle(2);
graphics.drawRect(-1, -1, ((48*12)+2), (576+2));
graphics.lineStyle();
graphics.beginFill(0xCCCCCC);
graphics.drawRect(0, 0, (48*12), 48);
graphics.endFill();
graphics.beginFill(0xBFBFBF);
graphics.drawRect(0, 48, (48*12), 48);
graphics.endFill();
graphics.beginFill(0xB3B3B3);
graphics.drawRect(0, 96, (48*12), 48);
graphics.endFill();
graphics.beginFill(0xA6A6A6);
graphics.drawRect(0, 144, (48*12), 48);
graphics.endFill();
graphics.beginFill(0x999999);
graphics.drawRect(0, 192, (48*12), 48);
graphics.endFill();
graphics.beginFill(0x8C8C8C);
graphics.drawRect(0, 240, (48*12), 48);
graphics.endFill();
graphics.beginFill(0x808080);
graphics.drawRect(0, 288, (48*12), 48);
graphics.endFill();
graphics.beginFill(0x737373);
graphics.drawRect(0, 336, (48*12), 48);
graphics.endFill();
graphics.beginFill(0x666666);
graphics.drawRect(0, 384, (48*12), 48);
graphics.endFill();
graphics.beginFill(0x595959);
graphics.drawRect(0, 432, (48*12), 48);
graphics.endFill();
graphics.beginFill(0x4D4D4D);
graphics.drawRect(0, 480, (48*12), 48);
graphics.endFill();
graphics.beginFill(0x404040);
graphics.drawRect(0, 528, (48*12), 48);
graphics.endFill();
(gridHighlight.parent == null) ? initGridHighlight() : null;
gridHighlight.graphics.clear();
gridHighlight.graphics.lineStyle(2, 0xFFFFFF);
(columnLock != 0) ? (gridHighlight.graphics.drawRect(($gridScale*columnLock)-1, -1, $gridScale+2, (($gridScale*$gridSize)+2))) : (gridHighlight.graphics.drawRect(($gridScale*_index)-1, -1, $gridScale+2, ($gridScale*$gridSize)+2));
}
public function onMouseMove($e:MouseEvent) :void
{
_index = parsePosition($e.stageX);
init();
}
public function initGridHighlight() :void
{
if (Buffer.GRID_HIGHLIGHT)
{
Buffer.CANVAS.addChild(gridHighlight)
}
}
public function parsePosition($loc:int) :int
{
var $indexY :int = -20;
var $gridMin :Point = Buffer.GRID_MARGIN;
var $gridMax :Point = Buffer.GRID_SIZE.add(Buffer.GRID_MARGIN);
var $gridScale :int = Buffer.GRID_SCALE;
if (Buffer.CANVAS.mouseX > ($gridScale * $gridMin.x) && Buffer.CANVAS.mouseY > ($gridScale * $gridMin.y) &&
Buffer.CANVAS.mouseX < ($gridScale * $gridMax.x) && Buffer.CANVAS.mouseY < ($gridScale * $gridMax.y))
{
var $trigger :Boolean = false;
var $targetY :Array = [];
var $resultY :Array = [];
var $tempLoc :int = -1;
for (var $:int=($gridMin.x-1); $<$gridMax.x; $++)
{
$targetY.push(($+0.475)*$gridScale);
$resultY.push(int(Math.abs($loc - $targetY[$-$gridMin.y])));
}
$tempLoc = Math.min.apply(null, $resultY);
for (var $$:int=($gridMin.x-1); $$<$gridMax.y; $$++)
{
($tempLoc == $resultY[$$-$gridMin.y] && $trigger == false) ? ($indexY = ($$-$gridMin.y), $trigger = true) : null;
($$==($gridMax.y-1) && $trigger == false) ? ($indexY = -20) : null;
}
}
return $indexY;
}
public function get columnLock() :int
{return _columnLock}
public function set columnLock($:int) :void
{_columnLock = $}
}
class ProgressPanel extends Sprite
{
public function ProgressPanel($x:Number, $y:Number)
{
addEventListener(Event.ADDED_TO_STAGE, addedToStage);
x = $x;
y = $y;
}
public function addedToStage($e:*) :void
{
removeEventListener(Event.ADDED_TO_STAGE, addedToStage);
init();
}
public function init() :void
{
graphics.clear();
graphics.lineStyle(2);
graphics.drawRect(-1, -1, 192+2, 576+2);
graphics.lineStyle();
graphics.beginFill(0xCCCCCC);
graphics.drawRect(0, 0, 192, 576);
graphics.endFill();
}
}
class GridNode extends Sprite
{
protected var _scale :int;
protected var _status :int;
protected var _color :Number;
protected var _border :Boolean;
protected var _initPos :Point;
protected var _scatterPos :Point;
private var prevColor :Number;
private var prevPos :Point = new Point();
private var thisPos :Point = new Point();
private var calcPos :Point = new Point();
public function GridNode($x:Number, $y:Number, $scale:Number)
{
addEventListener(Event.ADDED_TO_STAGE, addedToStage);
x = $x;
y = $y;
_status = 0;
_scale = $scale;
_color = 0xFFFFFF;
_border = false;
_initPos = new Point(int(x), int(y));
_scatterPos = new Point(int(120 + (Math.random()*600)), int(120 + (Math.random()*600)));
}
public function addedToStage($e:*) :void
{
removeEventListener(Event.ADDED_TO_STAGE, addedToStage);
init();
addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
}
public function init() :void
{
graphics.clear();
graphics.beginFill(color);
graphics.drawRect(0, 0, scale, scale);
graphics.endFill();
(border) ? (graphics.lineStyle(1, 0xFFFFFF), graphics.drawRect(0, 0, (scale), (scale))) : null;
width = height = scale;
}
private function onMouseDown($e:MouseEvent) :void
{
Buffer.CANVAS.removeEventListener(Event.ENTER_FRAME, Buffer.nodeTransitionBuffer)
Buffer.bringToFront(this);
prevPos = new Point($e.stageX, $e.stageY);
border = true;
initTransition();
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
private function onMouseMove($e:MouseEvent) :void
{
thisPos = new Point($e.stageX, $e.stageY);
calcPos = thisPos.subtract(prevPos);
x += int(calcPos.x);
y += int(calcPos.y);
prevPos = thisPos;
}
private function onMouseUp($e:MouseEvent) :void
{
stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
border = false;
Buffer.CANVAS.addEventListener(Event.ENTER_FRAME, Buffer.nodeTransitionBuffer)
}
private function initTransition() :void
{
switch (status)
{
case 0:
Buffer.scatterNodes(this);
break;
case 1:
statusTransition();
break;
}
}
public function statusTransition() :void
{
var $dist :Point = new Point();
var $normThreshold :int = 48;
var $marginX :Array; //since we're incrementing by the product of subtracting the distance between current pos & scattered pos,
var $marginY :Array; //we're going to provide 1 pixel margin instead of checking sign and writing verbose control-flow to catch it
var $a :Boolean;
var $b :Boolean;
switch (status)
{
case 0: //scatter
$marginX = [(_scatterPos.x - 1), (_scatterPos.x + 1)]; //[minX, maxX]
$marginY = [(_scatterPos.y - 1), (_scatterPos.y + 1)]; //[minY, maxY]
(x <= $marginX[0] || x >= $marginX[1]) ? (x -= int(x - _scatterPos.x)/4) : $a = true;
(y <= $marginY[0] || y >= $marginY[1]) ? (y -= int(y - _scatterPos.y)/4) : $b = true;
($a == true && $b == true) ? (mouseEnabled = true, status = 1) : null;
break;
case 1: //normalize
$dist = new Point(Math.abs((_initPos.x + 24) - (x + 24)), Math.abs((_initPos.y + 24) - (y + 24)));
if ($dist.x < $normThreshold && $dist.y < $normThreshold)
{
$marginX = [(_initPos.x - 1), (_initPos.x + 1)];
$marginY = [(_initPos.y - 1), (_initPos.y + 1)];
(x <= $marginX[0] || x >= $marginX[1]) ? (x -= int(x - _initPos.x)/4) : $a = true;
(y <= $marginY[0] || y >= $marginY[1]) ? (y -= int(y - _initPos.y)/4) : $b = true;
($a == true && $b == true) ? (x = _initPos.x, y = _initPos.y, mouseEnabled = false, status = 2) : null;
}
break;
case 2:
(Buffer.checkNodeStatus() == 0) ? Buffer.resetNodes() : null;
break;
/*
'case 2' denotes being normalized; once normalized, status should not return to 0 unless game/column completed,
look @ 'checkNodeStatus' under static Buffer.
'case 0' & '1' are incrementing the node, like i said earlier, by the product of their ever-smaller,
subtracted points (aka the distance) to the scattered/normalized positions, then dividing it to
provide a smooth transition over multiple frames.
Due to the fact that we're dividing the product of subtraction, and incrementing it on the node's position, the node will NEVER
reach the absolute position of our desired location (initPos/scatterPos), therefore providing a 1-pixel margin solves this problem.
Checking the sign of the product for distance, then using control-flow to increment over-step in such cases, will also solve this problem,
however, like I stated earlier; the latter solution is much more verbose.
*/
}
}
public function get scale() :Number
{return _scale}
public function get color() :Number
{return _color}
public function get border() :Boolean
{return _border}
public function get status() :int
{return _status}
public function get initPos() :Point
{return _initPos}
public function get scatterPos() :Point
{return _scatterPos}
public function set scale($:Number) :void
{_scale = $; init()}
public function set color($:Number) :void
{_color = $; init()}
public function set border($:Boolean) :void
{_border = $; init()}
public function set status($:int) :void
{_status = $}
public function set scatterPos($:Point) :void
{_scatterPos = $}
}
class Output extends TextField
{
private var textFormat :TextFormat;
protected var _x :Number;
protected var _y :Number;
protected var _font :String;
protected var _content :String;
public function Output($content:String, $x:Number = 1, $y:Number = 0, $font:String = "Helvetica")
{
addEventListener(Event.ADDED_TO_STAGE, addedToStage);
_x = $x;
_y = $y;
_font = $font;
_content = $content;
multiline = true;
autoSize = "left";
selectable = mouseEnabled = false;
antiAliasType = AntiAliasType.ADVANCED;
}
public function _init() :void
{
x = _x;
y = _y;
text = _content;
textFormat = new TextFormat(_font, null, 0xFFFFFF);
setTextFormat(textFormat);
}
public function addedToStage($e:Event) :void
{
removeEventListener(Event.ADDED_TO_STAGE, addedToStage);
_init();
}
public function get font() :String
{ return _font }
public function get nWidth() :Number
{ return width }
public function set font($:String) :void
{ _font = $; _init() }
public function set content($:String) :void
{ _content = $; _init() }
}