obelisk.js
Version:
JavaScript Library for Building Pixel Isometric Element with HTML5 Canvas
1,838 lines (1,433 loc) • 199 kB
JavaScript
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
/*jslint node: true*/
'use strict';
var AbstractColor, p;
AbstractColor = function () {
this.initialize();
};
p = AbstractColor.prototype;
// public properties
/**
* The inner colors for elements of certain primitive
*/
p.inner = null;
/**
* The border colors for elements of certain primitive
*/
p.border = null;
/**
* The borderHighlight colors for elements of certain primitive
*/
p.borderHighlight = null;
/**
* The left side colors for elements of certain primitive
*/
p.left = null;
/**
* The right side colors for elements of certain primitive
*/
p.right = null;
/**
* The horizontal colors for elements of certain primitive
*/
p.horizontal = null;
/**
* The left slot side colors for elements of certain primitive
*/
p.leftSlope = null;
/**
* The right slot side colors for elements of certain primitive
*/
p.rightSlope = null;
// constructor
p.initialize = function () {
return this;
};
// public methods
p.toString = function () {
return '[AbstractColor]';
};
module.exports = AbstractColor;
},{}],2:[function(require,module,exports){
/*jslint node: true*/
'use strict';
var AbstractColor = require('./AbstractColor');
var ColorGeom = require('../utils/ColorGeom');
var CubeColor, p;
CubeColor = function (border, borderHighlight, left, right, horizontal) {
this.initialize(border, borderHighlight, left, right, horizontal);
};
p = CubeColor.prototype = new AbstractColor();
// public properties
p.BRIGHTNESS_GAIN = -20;
// constructor
p.initialize = function (border, borderHighlight, left, right, horizontal) {
this.border = ColorGeom.get32(border === undefined ? 0x878787 : border);
this.borderHighlight = ColorGeom.get32(borderHighlight === undefined ? 0xFFFFFF : borderHighlight);
this.left = ColorGeom.get32(left === undefined ? 0xC9CFD0 : left);
this.right = ColorGeom.get32(right === undefined ? 0xE3E3E3 : right);
this.horizontal = ColorGeom.get32(horizontal === undefined ? 0xEEEFF0 : horizontal);
return this;
};
// public methods
p.getByHorizontalColor = function (horizontal) {
return new CubeColor(
ColorGeom.applyBrightness(horizontal, this.BRIGHTNESS_GAIN * 4),
//apply hightlight
ColorGeom.applyBrightness(horizontal, 0, true),
ColorGeom.applyBrightness(horizontal, this.BRIGHTNESS_GAIN * 2),
ColorGeom.applyBrightness(horizontal, this.BRIGHTNESS_GAIN),
horizontal
);
};
p.toString = function () {
return '[CubeColor]';
};
module.exports = CubeColor;
},{"../utils/ColorGeom":39,"./AbstractColor":1}],3:[function(require,module,exports){
/*jslint node: true*/
'use strict';
var AbstractColor = require('./AbstractColor');
var ColorGeom = require('../utils/ColorGeom');
var LineColor, p;
LineColor = function (border, inner) {
this.initialize(border, inner);
};
p = LineColor.prototype = new AbstractColor();
// public properties
// constructor
p.initialize = function (border) {
this.border = ColorGeom.get32(border === undefined ? 0x878787 : border);
return this;
};
p.toString = function () {
return '[LineColor]';
};
module.exports = LineColor;
},{"../utils/ColorGeom":39,"./AbstractColor":1}],4:[function(require,module,exports){
/*jslint node: true*/
'use strict';
var AbstractColor = require('./AbstractColor');
var ColorGeom = require('../utils/ColorGeom');
var PyramidColor, p;
PyramidColor = function (border, borderHighlight, left, right) {
this.initialize(border, borderHighlight, left, right);
};
p = PyramidColor.prototype = new AbstractColor();
// public properties
p.BRIGHTNESS_GAIN = -20;
// constructor
p.initialize = function (border, borderHighlight, left, right) {
this.border = ColorGeom.get32(border === undefined ? 0x949698 : border);
this.borderHighlight = ColorGeom.get32(borderHighlight === undefined ? 0xFFFFFF : borderHighlight);
this.left = ColorGeom.get32(left === undefined ? 0xE6E8E9 : left);
this.right = ColorGeom.get32(right === undefined ? 0xEEEFF0 : right);
return this;
};
// public methods
p.getByRightColor = function (right) {
return new PyramidColor(
ColorGeom.applyBrightness(right, this.BRIGHTNESS_GAIN * 4),
//apply hightlight
ColorGeom.applyBrightness(right, 0, true),
ColorGeom.applyBrightness(right, this.BRIGHTNESS_GAIN),
right
);
};
p.toString = function () {
return '[PyramidColor]';
};
module.exports = PyramidColor;
},{"../utils/ColorGeom":39,"./AbstractColor":1}],5:[function(require,module,exports){
/*jslint node: true*/
'use strict';
var AbstractColor = require('./AbstractColor');
var ColorGeom = require('../utils/ColorGeom');
var SideColor, p;
SideColor = function (border, inner) {
this.initialize(border, inner);
};
p = SideColor.prototype = new AbstractColor();
// public properties
p.BRIGHTNESS_GAIN = -20;
// constructor
p.initialize = function (border, inner) {
this.border = ColorGeom.get32(border === undefined ? 0x878787 : border);
this.inner = ColorGeom.get32(inner === undefined ? 0xEEEEEE : inner);
return this;
};
// public methods
p.getByInnerColor = function (inner) {
return new SideColor(
ColorGeom.applyBrightness(inner, this.BRIGHTNESS_GAIN * 4),
inner
);
};
p.toString = function () {
return '[SideColor]';
};
module.exports = SideColor;
},{"../utils/ColorGeom":39,"./AbstractColor":1}],6:[function(require,module,exports){
/*jslint node: true*/
'use strict';
var AbstractColor = require('./AbstractColor');
var ColorGeom = require('../utils/ColorGeom');
var SlopeColor, p;
SlopeColor = function (border, borderHighlight, left, right, leftSlope, rightSlope) {
this.initialize(border, borderHighlight, left, right, leftSlope, rightSlope);
};
p = SlopeColor.prototype = new AbstractColor();
// public properties
p.BRIGHTNESS_GAIN = -20;
// constructor
p.initialize = function (border, borderHighlight, left, right, leftSlope, rightSlope) {
this.border = ColorGeom.get32(border === undefined ? 0x949698 : border);
this.borderHighlight = ColorGeom.get32(borderHighlight === undefined ? 0xFFFFFF : borderHighlight);
this.left = ColorGeom.get32(left === undefined ? 0xC9CFD0 : left);
this.right = ColorGeom.get32(right === undefined ? 0xE6E8E9 : right);
this.leftSlope = ColorGeom.get32(leftSlope === undefined ? 0xDBDBDB : leftSlope);
this.rightSlope = ColorGeom.get32(rightSlope === undefined ? 0xDBDBDB : rightSlope);
return this;
};
// public methods
/*
* horizontal side doesn't actually exist in the Slope primitive
* you can assign the same horizontal color as cube
* so that you will be able to arrange the slope with cube
*/
p.getByHorizontalColor = function (horizontal) {
return new SlopeColor(
ColorGeom.applyBrightness(horizontal, this.BRIGHTNESS_GAIN * 4),
//apply hightlight
ColorGeom.applyBrightness(horizontal, 0, true),
ColorGeom.applyBrightness(horizontal, this.BRIGHTNESS_GAIN * 2),
ColorGeom.applyBrightness(horizontal, this.BRIGHTNESS_GAIN),
ColorGeom.applyBrightness(horizontal, this.BRIGHTNESS_GAIN * 1.5),
ColorGeom.applyBrightness(horizontal, this.BRIGHTNESS_GAIN * 0.5)
);
};
p.toString = function () {
return '[SlopeColor]';
};
module.exports = SlopeColor;
},{"../utils/ColorGeom":39,"./AbstractColor":1}],7:[function(require,module,exports){
/*jslint node: true*/
'use strict';
var AbstractDimension, p;
AbstractDimension = function () {
this.initialize();
};
p = AbstractDimension.prototype;
// public properties
/**
* The x Axis dimensions in 22.6 degrees coordinate
*/
p.xAxis = null;
/**
* The y Axis dimensions in 22.6 degrees coordinate
*/
p.yAxis = null;
/**
* The z Axis dimensions in 22.6 degrees coordinate
*/
p.zAxis = null;
/**
* Pyramid tall mode
*/
p.tall = false;
// constructor
p.initialize = function () {
return this;
};
// public methods
p.toString = function () {
return '[AbstractDimension]';
};
module.exports = AbstractDimension;
},{}],8:[function(require,module,exports){
/*jslint node: true*/
'use strict';
var AbstractDimension = require('./AbstractDimension');
var BrickDimension, p;
BrickDimension = function (xAxis, yAxis) {
this.initialize(xAxis, yAxis);
};
p = BrickDimension.prototype = new AbstractDimension();
// constructor
p.initialize = function (xAxis, yAxis) {
this.xAxis = xAxis || 30;
this.yAxis = yAxis || 30;
if (this.xAxis % 2 === 1 || this.yAxis % 2 === 1) {
throw new Error('x,yAxis must be even number');
}
// xAxis || yAxis = 4 floodFill could not be applied
if (this.xAxis <= 4 || this.yAxis <= 4) {
throw new Error('dimension is too small');
}
return this;
};
p.toString = function () {
return '[BrickDimension]';
};
module.exports = BrickDimension;
},{"./AbstractDimension":7}],9:[function(require,module,exports){
/*jslint node: true*/
'use strict';
var AbstractDimension = require('./AbstractDimension');
var CubeDimension, p;
CubeDimension = function (xAxis, yAxis, zAxis) {
this.initialize(xAxis, yAxis, zAxis);
};
p = CubeDimension.prototype = new AbstractDimension();
// constructor
p.initialize = function (xAxis, yAxis, zAxis) {
this.xAxis = xAxis || 30;
this.yAxis = yAxis || 30;
this.zAxis = zAxis || 30;
if (this.xAxis % 2 === 1 || this.yAxis % 2 === 1) {
throw new Error('x,yAxis must be even number');
}
// xAxis || yAxis = 4 floodFill could not be applied
if (this.xAxis <= 4 || this.yAxis <= 4 || this.zAxis <= 2) {
throw new Error('dimension is too small');
}
return this;
};
p.toString = function () {
return '[CubeDimension]';
};
module.exports = CubeDimension;
},{"./AbstractDimension":7}],10:[function(require,module,exports){
/*jslint node: true*/
'use strict';
var AbstractDimension = require('./AbstractDimension');
var LineXDimension, p;
LineXDimension = function (axis) {
this.initialize(axis);
};
p = LineXDimension.prototype = new AbstractDimension();
// constructor
p.initialize = function (xAxis) {
this.xAxis = xAxis || 30;
if (this.xAxis % 2 === 1) {
throw new Error('xAxis must be even number');
}
if (this.xAxis < 2) {
throw new Error('dimension is too small');
}
return this;
};
p.toString = function () {
return '[LineXDimension]';
};
module.exports = LineXDimension;
},{"./AbstractDimension":7}],11:[function(require,module,exports){
/*jslint node: true*/
'use strict';
var AbstractDimension = require('./AbstractDimension');
var LineYDimension, p;
LineYDimension = function (axis) {
this.initialize(axis);
};
p = LineYDimension.prototype = new AbstractDimension();
// constructor
p.initialize = function (yAxis) {
this.yAxis = yAxis || 30;
if (this.yAxis % 2 === 1) {
throw new Error('yAxis must be even number');
}
if (this.yAxis < 2) {
throw new Error('dimension is too small');
}
return this;
};
p.toString = function () {
return '[LineYDimension]';
};
module.exports = LineYDimension;
},{"./AbstractDimension":7}],12:[function(require,module,exports){
/*jslint node: true*/
'use strict';
var AbstractDimension = require('./AbstractDimension');
var LineZDimension, p;
LineZDimension = function (axis) {
this.initialize(axis);
};
p = LineZDimension.prototype = new AbstractDimension();
// constructor
p.initialize = function (zAxis) {
this.zAxis = zAxis || 30;
if (this.zAxis <= 0) {
throw new Error('dimension is too small');
}
return this;
};
p.toString = function () {
return '[LineZDimension]';
};
module.exports = LineZDimension;
},{"./AbstractDimension":7}],13:[function(require,module,exports){
/*jslint node: true*/
'use strict';
var AbstractDimension = require('./AbstractDimension');
var PyramidDimension, p;
PyramidDimension = function (axis, tall) {
this.initialize(axis, tall);
};
p = PyramidDimension.prototype = new AbstractDimension();
// constructor
p.initialize = function (axis, tall) {
this.xAxis = axis || 30;
this.yAxis = axis || 30;
this.tall = tall || false;
if (this.xAxis % 2 === 1) {
throw new Error('axis must be even number');
}
if (this.xAxis <= 4) {
throw new Error('dimension is too small');
}
return this;
};
p.toString = function () {
return '[PyramidDimension]';
};
module.exports = PyramidDimension;
},{"./AbstractDimension":7}],14:[function(require,module,exports){
/*jslint node: true*/
'use strict';
var AbstractDimension = require('./AbstractDimension');
var SideXDimension, p;
SideXDimension = function (xAxis, zAxis) {
this.initialize(xAxis, zAxis);
};
p = SideXDimension.prototype = new AbstractDimension();
// constructor
p.initialize = function (xAxis, zAxis) {
this.xAxis = xAxis || 30;
this.zAxis = zAxis || 30;
if (this.xAxis % 2 === 1) {
throw new Error('xAxis must be even number');
}
// xAxis || zAxis = 4 floodFill could not be applied
if (this.xAxis <= 4 || this.zAxis <= 2) {
throw new Error('dimension is too small');
}
return this;
};
p.toString = function () {
return '[SideXDimension]';
};
module.exports = SideXDimension;
},{"./AbstractDimension":7}],15:[function(require,module,exports){
/*jslint node: true*/
'use strict';
var AbstractDimension = require('./AbstractDimension');
var SideYDimension, p;
SideYDimension = function (yAxis, zAxis) {
this.initialize(yAxis, zAxis);
};
p = SideYDimension.prototype = new AbstractDimension();
// constructor
p.initialize = function (yAxis, zAxis) {
this.yAxis = yAxis || 30;
this.zAxis = zAxis || 30;
if (this.yAxis % 2 === 1) {
throw new Error('yAxis must be even number');
}
// yAxis || zAxis = 4 floodFill could not be applied
if (this.yAxis <= 4 || this.zAxis <= 2) {
throw new Error('dimension is too small');
}
return this;
};
p.toString = function () {
return '[SideYDimension]';
};
module.exports = SideYDimension;
},{"./AbstractDimension":7}],16:[function(require,module,exports){
/*jslint node: true*/
'use strict';
var AbstractDimension = require('./AbstractDimension');
var SlopeDimension, p;
SlopeDimension = function (xAxis, yAxis) {
this.initialize(xAxis, yAxis);
};
p = SlopeDimension.prototype = new AbstractDimension();
// constructor
p.initialize = function (xAxis, yAxis) {
this.xAxis = xAxis || 30;
this.yAxis = yAxis || 30;
if (this.xAxis % 2 === 1 || this.yAxis % 2 === 1) {
throw new Error('xAxis and yAxis must be even number');
}
if (this.xAxis <= 4 || this.yAxis <= 4) {
throw new Error('dimension is too small');
}
return this;
};
p.toString = function () {
return '[SlopeDimension]';
};
module.exports = SlopeDimension;
},{"./AbstractDimension":7}],17:[function(require,module,exports){
/*jslint node: true*/
'use strict';
var CanvasManager = require('../utils/CanvasManager');
var BitmapData, p;
BitmapData = function (w, h, useDefaultCanvas) {
this.initialize(w, h, useDefaultCanvas);
};
p = BitmapData.prototype;
// public property
p.imageData = null;
p.canvas = null;
p.context = null;
// constructor
p.initialize = function (w, h, useDefaultCanvas) {
if (w === undefined || h === undefined) {
throw new Error('BitmapData width or height is missing');
}
if (useDefaultCanvas) {
this.canvas = CanvasManager.getDefaultCanvas();
} else {
this.canvas = CanvasManager.getNewCanvas();
}
this.canvas.setAttribute('width', w);
this.canvas.setAttribute('height', h);
this.context = this.canvas.getContext('2d');
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
this.context.mozImageSmoothingEnabled = false;
this.context.msImageSmoothingEnabled = false;
this.context.imageSmoothingEnabled = false;
this.imageData = this.context.createImageData(w, h);
return this;
};
p.setPixel = function (posX, posY, color) {
var index = (posY * this.imageData.width + posX) * 4;
this.setPixelByIndex(index, color);
};
p.setPixelByIndex = function (index, color) {
var pixels = this.imageData.data;
pixels[index] = (color >>> 16) & 0xFF;
pixels[index + 1] = (color >>> 8) & 0xFF;
pixels[index + 2] = (color >>> 0) & 0xFF;
pixels[index + 3] = (color >>> 24) & 0xFF;
};
p.checkPixelAvailable = function (x, y) {
var index = (y * this.imageData.width + x) * 4;
return this.imageData.data[index + 3] === 0;
};
p.floodFill = function (posX, posY, color) {
if (((color >>> 24) & 0xFF) === 0x00) {
// transparent flood fill
return;
}
var x = posX, y = posY,
stack = [],
nowCol = [],
prevCol = [],
col, row, matchFlag, newStart,
w = this.imageData.width,
h = this.imageData.height,
i, j;
// bound reach
if (x < 0 || y < 0 || x >= w || y >= h) {
return;
}
// first point check fail
if (!this.checkPixelAvailable(x, y)) {
throw new Error('Start point for flood fill is already filled');
}
// left side flood fill
for (col = x; col >= 0; col -= 1) {
// top side
for (row = y; row >= 0; row -= 1) {
if (this.checkPixelAvailable(col, row)) {
// available pixel
stack.push((row * w + col) * 4);
nowCol.push(row);
} else {
// first one is invalid pixel && not at col top
if (row === y && this.checkPixelAvailable(col + 1, row - 1)) {
// next one is valid
if (this.checkPixelAvailable(col, row - 1)) {
newStart = row - 1;
} else {
if (this.checkPixelAvailable(col + 1, row - 2)) {
newStart = row - 2;
} else {
// fail, assign max value to avoid loop below
newStart = -1;
}
}
for (row = newStart; row >= 0; row -= 1) {
if (this.checkPixelAvailable(col, row)) {
// available pixel
stack.push((row * w + col) * 4);
nowCol.push(row);
} else {
break;
}
}
}
break;
}
}
// bottom side
for (row = y; row < h; row += 1) {
if (this.checkPixelAvailable(col, row)) {
// available pixel
stack.push((row * w + col) * 4);
nowCol.push(row);
} else {
// first one is invalid pixel && not at col bottom
if (row === y && this.checkPixelAvailable(col + 1, row + 1)) {
// next one is valid
if (this.checkPixelAvailable(col, row + 1)) {
newStart = row + 1;
} else {
if (this.checkPixelAvailable(col + 1, row + 2)) {
newStart = row + 2;
} else {
// fail, assign max value to avoid loop below
newStart = h;
}
}
for (row = newStart; row < h; row += 1) {
if (this.checkPixelAvailable(col, row)) {
// available pixel
stack.push((row * w + col) * 4);
nowCol.push(row);
} else {
break;
}
}
}
break;
}
}
// compare with previous column
// for first column
// the given point should be inside the container
if (col === x) {
prevCol = nowCol.concat();
}
matchFlag = false;
for (i = 0; i < prevCol.length; i += 1) {
for (j = 0; j < prevCol.length; j += 1) {
if (nowCol[j] === prevCol[i]) {
matchFlag = true;
y = prevCol[i];
break;
}
}
if (matchFlag) {
break;
}
}
if (matchFlag) {
prevCol = nowCol.concat();
nowCol = [];
} else {
// bound reach
break;
}
}
// reset start point
x = posX;
y = posY;
prevCol = [];
nowCol = [];
// right side flood fill
for (col = x; col < w; col += 1) {
// top side
for (row = y; row >= 0; row -= 1) {
if (this.checkPixelAvailable(col, row)) {
// available pixel
stack.push((row * w + col) * 4);
nowCol.push(row);
} else {
// first one is invalid pixel && not at col top
if (row === y && this.checkPixelAvailable(col - 1, row - 1)) {
// next one is valid
if (this.checkPixelAvailable(col, row - 1)) {
newStart = row - 1;
} else {
if (this.checkPixelAvailable(col - 1, row - 2)) {
newStart = row - 2;
} else {
// fail, assign max value to avoid loop below
newStart = -1;
}
}
for (row = newStart; row >= 0; row -= 1) {
if (this.checkPixelAvailable(col, row)) {
// available pixel
stack.push((row * w + col) * 4);
nowCol.push(row);
} else {
break;
}
}
}
break;
}
}
// bottom side
for (row = y; row < h; row += 1) {
if (this.checkPixelAvailable(col, row)) {
// available pixel
stack.push((row * w + col) * 4);
nowCol.push(row);
} else {
// first one is invalid pixel && not at col bottom
if (row === y && this.checkPixelAvailable(col - 1, row + 1)) {
// next one is valid
if (this.checkPixelAvailable(col, row + 1)) {
newStart = row + 1;
} else {
if (this.checkPixelAvailable(col - 1, row + 2)) {
newStart = row + 2;
} else {
// fail, assign max value to avoid loop below
newStart = h;
}
}
for (row = newStart; row < h; row += 1) {
if (this.checkPixelAvailable(col, row)) {
// available pixel
stack.push((row * w + col) * 4);
nowCol.push(row);
} else {
break;
}
}
}
break;
}
}
// compare with previous column
// for first column
// the given point should be inside the container
if (col === x) {
prevCol = nowCol.concat();
}
matchFlag = false;
for (i = 0; i < prevCol.length; i += 1) {
for (j = 0; j < prevCol.length; j += 1) {
if (nowCol[j] === prevCol[i]) {
matchFlag = true;
y = prevCol[i];
break;
}
}
if (matchFlag) {
break;
}
}
if (matchFlag) {
prevCol = nowCol.concat();
nowCol = [];
} else {
// bound reach
break;
}
}
// fill image data
for (i = 0; i < stack.length; i += 1) {
this.setPixelByIndex(stack[i], color);
}
};
p.toString = function () {
return '[BitmapData]';
};
module.exports = BitmapData;
},{"../utils/CanvasManager":37}],18:[function(require,module,exports){
/*jslint node: true*/
'use strict';
var Point3D = require('../geom/Point3D');
var PixelObject, p;
PixelObject = function (primitive, point3D) {
this.initialize(primitive, point3D);
};
p = PixelObject.prototype;
// public properties
p.x = null;
p.y = null;
p.canvas = null;
// constructor
p.initialize = function (primitive, point3D) {
if (!primitive) {
throw new Error('Primitive is not defined');
}
var p3D = point3D || new Point3D();
this.canvas = primitive.canvas;
this.x = primitive.matrix.tx + p3D.x - p3D.y;
this.y = primitive.matrix.ty + Math.floor(p3D.x / 2 + p3D.y / 2) - p3D.z;
return this;
};
// public methods
p.toString = function () {
return '[PixelObject]';
};
// private methods
module.exports = PixelObject;
},{"../geom/Point3D":22}],19:[function(require,module,exports){
/*jslint node: true*/
/*global jQuery:true*/
'use strict';
var Point = require('../geom/Point');
var PixelObject = require('../display/PixelObject');
var PixelView, p;
PixelView = function (canvas, point) {
this.initialize(canvas, point);
};
p = PixelView.prototype;
// public properties
p.canvas = null;
p.context = null;
p.point = null;
// constructor
p.initialize = function (canvas, point) {
if (!canvas) {
throw new Error('Canvas is not defined');
}
try {
if (canvas instanceof jQuery) {
canvas = canvas.get(0);
}
} catch (ignore) {
}
this.canvas = canvas;
this.context = this.canvas.getContext('2d');
this.context.mozImageSmoothingEnabled = false;
this.context.msImageSmoothingEnabled = false;
this.context.imageSmoothingEnabled = false;
this.point = point || new Point(0, 0);
return this;
};
// public methods
p.renderObject = function (primitive, point3D) {
var po = new PixelObject(primitive, point3D);
this.context.drawImage(po.canvas, this.point.x + po.x, this.point.y + po.y);
};
p.clear = function () {
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
};
p.toString = function () {
return '[PixelView]';
};
module.exports = PixelView;
},{"../display/PixelObject":18,"../geom/Point":21}],20:[function(require,module,exports){
/*jslint node: true*/
'use strict';
var Matrix, p;
Matrix = function (a, b, c, d, tx, ty) {
this.initialize(a, b, c, d, tx, ty);
};
p = Matrix.prototype;
// public properties:
/**
* Position (0, 0) in a 3x3 matrix.
* @property a
* @type Number
**/
p.a = 1;
/**
* Position (0, 1) in a 3x3 matrix.
* @property b
* @type Number
**/
p.b = 0;
/**
* Position (1, 0) in a 3x3 matrix.
* @property c
* @type Number
**/
p.c = 0;
/**
* Position (1, 1) in a 3x3 matrix.
* @property d
* @type Number
**/
p.d = 1;
/**
* Position (2, 0) in a 3x3 matrix.
* @property tx
* @type Number
**/
p.tx = 0;
/**
* Position (2, 1) in a 3x3 matrix.
* @property ty
* @type Number
**/
p.ty = 0;
// constructor
p.initialize = function (a, b, c, d, tx, ty) {
this.a = (a === undefined) ? 1 : a;
this.b = b || 0;
this.c = c || 0;
this.d = (d === undefined) ? 1 : d;
this.tx = tx || 0;
this.ty = ty || 0;
return this;
};
// public methods
p.toString = function () {
return '[Matrix]';
};
module.exports = Matrix;
},{}],21:[function(require,module,exports){
/*jslint node: true*/
'use strict';
var Point, p;
Point = function (x, y) {
this.initialize(x, y);
};
p = Point.prototype;
// public properties
p.x = 0;
p.y = 0;
// constructor
p.initialize = function (x, y) {
this.x = (x === undefined ? 0 : x);
this.y = (y === undefined ? 0 : y);
return this;
};
// public methods
p.toString = function () {
return '[Point x : ' + this.x + ', y : ' + this.y + ']';
};
module.exports = Point;
},{}],22:[function(require,module,exports){
/*jslint node: true*/
'use strict';
var Point = require('./Point');
var Point3D, p;
Point3D = function (x, y, z) {
this.initialize(x, y, z);
};
p = Point3D.prototype;
// public properties
p.x = 0;
p.y = 0;
p.z = 0;
// constructor
p.initialize = function (x, y, z) {
this.x = (x === undefined ? 0 : x);
this.y = (y === undefined ? 0 : y);
this.z = (z === undefined ? 0 : z);
return this;
};
// public methods
p.toGlobalCoordinates = function (offset) {
var p2D = new Point(
this.x - this.y,
Math.floor(this.x / 2 + this.y / 2) - this.z
);
if (offset !== undefined) {
p2D.x = p2D.x + offset.x;
p2D.y = p2D.y + offset.y;
}
return p2D;
};
p.toString = function () {
return '[Point3D x : ' + this.x + ', y : ' + this.y + ', z: ' + this.z + ']';
};
module.exports = Point3D;
},{"./Point":21}],23:[function(require,module,exports){
/*jslint node: true*/
/*global window:true*/
'use strict';
/**
* @namespace obelisk
**/
var obelisk = {};
obelisk.Cube = require('./primitives/Cube');
obelisk.Brick = require('./primitives/Brick');
obelisk.Pyramid = require('./primitives/Pyramid');
obelisk.LineX = require('./primitives/LineX');
obelisk.LineY = require('./primitives/LineY');
obelisk.LineZ = require('./primitives/LineZ');
obelisk.SideX = require('./primitives/SideX');
obelisk.SideY = require('./primitives/SideY');
obelisk.SlopeEast = require('./primitives/SlopeEast');
obelisk.SlopeNorth = require('./primitives/SlopeNorth');
obelisk.SlopeSouth = require('./primitives/SlopeSouth');
obelisk.SlopeWest = require('./primitives/SlopeWest');
obelisk.ColorPattern = require('./utils/ColorPattern');
obelisk.ColorGeom = require('./utils/ColorGeom');
obelisk.CanvasManager = require('./utils/CanvasManager');
obelisk.CanvasTool = require('./utils/CanvasTool');
obelisk.Matrix = require('./geom/Matrix');
obelisk.Point = require('./geom/Point');
obelisk.Point3D = require('./geom/Point3D');
obelisk.PixelView = require('./display/PixelView');
obelisk.PixelObject = require('./display/PixelObject');
obelisk.BitmapData = require('./display/BitmapData');
obelisk.BrickDimension = require('./dimensions/BrickDimension');
obelisk.CubeDimension = require('./dimensions/CubeDimension');
obelisk.PyramidDimension = require('./dimensions/PyramidDimension');
obelisk.LineXDimension = require('./dimensions/LineXDimension');
obelisk.LineYDimension = require('./dimensions/LineYDimension');
obelisk.LineZDimension = require('./dimensions/LineZDimension');
obelisk.SideXDimension = require('./dimensions/SideXDimension');
obelisk.SideYDimension = require('./dimensions/SideYDimension');
obelisk.SlopeDimension = require('./dimensions/SlopeDimension');
obelisk.LineColor = require('./colors/LineColor');
obelisk.CubeColor = require('./colors/CubeColor');
obelisk.PyramidColor = require('./colors/PyramidColor');
obelisk.SideColor = require('./colors/SideColor');
obelisk.SlopeColor = require('./colors/SlopeColor');
window.obelisk = obelisk;
module.exports = obelisk;
},{"./colors/CubeColor":2,"./colors/LineColor":3,"./colors/PyramidColor":4,"./colors/SideColor":5,"./colors/SlopeColor":6,"./dimensions/BrickDimension":8,"./dimensions/CubeDimension":9,"./dimensions/LineXDimension":10,"./dimensions/LineYDimension":11,"./dimensions/LineZDimension":12,"./dimensions/PyramidDimension":13,"./dimensions/SideXDimension":14,"./dimensions/SideYDimension":15,"./dimensions/SlopeDimension":16,"./display/BitmapData":17,"./display/PixelObject":18,"./display/PixelView":19,"./geom/Matrix":20,"./geom/Point":21,"./geom/Point3D":22,"./primitives/Brick":25,"./primitives/Cube":26,"./primitives/LineX":27,"./primitives/LineY":28,"./primitives/LineZ":29,"./primitives/Pyramid":30,"./primitives/SideX":31,"./primitives/SideY":32,"./primitives/SlopeEast":33,"./primitives/SlopeNorth":34,"./primitives/SlopeSouth":35,"./primitives/SlopeWest":36,"./utils/CanvasManager":37,"./utils/CanvasTool":38,"./utils/ColorGeom":39,"./utils/ColorPattern":40}],24:[function(require,module,exports){
/*jslint node: true*/
'use strict';
var AbstractPrimitive, p;
AbstractPrimitive = function () {
this.initialize();
};
p = AbstractPrimitive.prototype;
// public properties
/**
* the canvas for drawImage to any canvas
*/
p.canvas = null;
// protect properties
/**
* the width of the bitmap in 2d flash coordinate
*/
p.w = null;
/**
* the height of the bitmap in 2d flash coordinate
*/
p.h = null;
/**
* the dimension of primitive in 3d pixel coordinate
*/
p.dimension = null;
/**
* the color obj of the primitive
*/
p.color = null;
/**
* the border option of the primitive
*/
p.border = null;
/**
* the source bitmapdata contains pixel graphic
*/
p.bitmapData = null;
/**
* the preserve canvas option
*/
p.useDefaultCanvas = null;
/**
* the matrix offset between the bitmap and the 3d pixel coordinate ZERO point
*/
p.matrix = null;
// constructor
p.initialize = function () {
return this;
};
// public methods
p.toString = function () {
return '[AbstractPrimitive]';
};
module.exports = AbstractPrimitive;
},{}],25:[function(require,module,exports){
/*jslint node: true*/
'use strict';
var BrickDimension = require('../dimensions/BrickDimension');
var SideColor = require('../colors/SideColor');
var Matrix = require('../geom/Matrix');
var BitmapData = require('../display/BitmapData');
var AbstractPrimitive = require('./AbstractPrimitive');
var Brick, p;
Brick = function (dimension, color, border, useDefaultCanvas) {
this.initialize(dimension, color, border, useDefaultCanvas);
};
p = Brick.prototype = new AbstractPrimitive();
// public properties
// constructor
p.initialize = function (dimension, color, border, useDefaultCanvas) {
this.initRender(dimension, color, border, useDefaultCanvas);
this.initRectangle();
this.initBitmapData();
this.build();
this.renderBitmapDataForCanvas();
return this;
};
// private method
p.initRender = function (dimension, color, border, useDefaultCanvas) {
this.useDefaultCanvas = useDefaultCanvas || false;
this.border = border || border === undefined;
this.dimension = dimension === undefined ? new BrickDimension() : dimension;
this.color = color === undefined ? new SideColor() : color;
};
p.initRectangle = function () {
this.w = this.dimension.xAxis + this.dimension.yAxis;
this.h = (this.dimension.xAxis + this.dimension.yAxis) / 2;
// 22.6 degrees implementation
this.w -= 2;
this.h -= 1;
// the matrix offset between the bitmap and the 3d pixel coordinate ZERO point
this.matrix = new Matrix();
this.matrix.tx = -this.dimension.yAxis + 2;
this.matrix.ty = 0;
};
p.initBitmapData = function () {
this.bitmapData = new BitmapData(this.w, this.h, this.useDefaultCanvas);
};
p.renderBitmapDataForCanvas = function () {
this.bitmapData.context.putImageData(this.bitmapData.imageData, 0, 0);
this.canvas = this.bitmapData.canvas;
};
p.build = function () {
var xOffsetInner, yOffsetInner, xOffsetOut, yOffsetOut, i, j, borderColor;
xOffsetInner = this.dimension.yAxis - 2;
yOffsetInner = 0;
xOffsetOut = this.dimension.xAxis - 1;
yOffsetOut = this.h - 1;
borderColor = this.border ? this.color.border : this.color.inner;
//x axis
for (i = 0; i < this.dimension.xAxis; i += 1) {
this.bitmapData.setPixel(xOffsetInner + i, yOffsetInner + Math.floor(i / 2), borderColor);
this.bitmapData.setPixel(xOffsetOut - i, yOffsetOut - Math.floor(i / 2), borderColor);
}
//y axis
for (j = 0; j < this.dimension.yAxis; j += 1) {
this.bitmapData.setPixel(xOffsetInner + 1 - j, yOffsetInner + Math.floor(j / 2), borderColor);
this.bitmapData.setPixel(xOffsetOut - 1 + j, yOffsetOut - Math.floor(j / 2), borderColor);
}
//fill an pixel graphic enclosed
this.bitmapData.floodFill(Math.floor(this.w / 2), Math.floor(this.h / 2), this.color.inner);
};
// public methods
p.toString = function () {
return '[Brick]';
};
module.exports = Brick;
},{"../colors/SideColor":5,"../dimensions/BrickDimension":8,"../display/BitmapData":17,"../geom/Matrix":20,"./AbstractPrimitive":24}],26:[function(require,module,exports){
/*jslint node: true*/
'use strict';
var CubeDimension = require('../dimensions/CubeDimension');
var BrickDimension = require('../dimensions/BrickDimension');
var SideXDimension = require('../dimensions/SideXDimension');
var SideYDimension = require('../dimensions/SideYDimension');
var CubeColor = require('../colors/CubeColor');
var SideColor = require('../colors/SideColor');
var Matrix = require('../geom/Matrix');
var PixelObject = require('../display/PixelObject');
var BitmapData = require('../display/BitmapData');
var AbstractPrimitive = require('./AbstractPrimitive');
var Brick = require('./Brick');
var SideX = require('./SideX');
var SideY = require('./SideY');
var Cube, p;
Cube = function (dimension, color, border, useDefaultCanvas) {
this.initialize(dimension, color, border, useDefaultCanvas);
};
p = Cube.prototype = new AbstractPrimitive();
// public properties
// constructor
p.initialize = function (dimension, color, border, useDefaultCanvas) {
this.initRender(dimension, color, border, useDefaultCanvas);
this.initRectangle();
this.initBitmapData();
this.build();
this.renderBitmapDataForCanvas();
return this;
};
// private method
p.initRender = function (dimension, color, border, useDefaultCanvas) {
this.useDefaultCanvas = useDefaultCanvas || false;
this.border = border || border === undefined;
this.dimension = dimension === undefined ? new CubeDimension() : dimension;
this.color = color === undefined ? new CubeColor() : color;
};
p.initRectangle = function () {
this.w = this.dimension.xAxis + this.dimension.yAxis;
this.h = this.dimension.zAxis + (this.dimension.xAxis + this.dimension.yAxis) / 2;
// 22.6 degrees implementation
this.w -= 2;
this.h -= 1;
// the matrix offset between the bitmap and the 3d pixel coordinate ZERO point
this.matrix = new Matrix();
this.matrix.tx = -this.dimension.yAxis + 2;
this.matrix.ty = -this.dimension.zAxis;
};
p.initBitmapData = function () {
this.bitmapData = new BitmapData(this.w, this.h, this.useDefaultCanvas);
};
p.renderBitmapDataForCanvas = function () {
this.canvas = this.bitmapData.canvas;
};
p.build = function () {
var brick, sideX, sideY, poBrick, poX, poY, ctx, bmd, offsetX, offsetY,
i, j, k;
// horizontal layer
brick = new Brick(
new BrickDimension(this.dimension.xAxis, this.dimension.yAxis),
new SideColor(this.color.border, this.color.horizontal),
this.border
);
// left side
sideX = new SideX(
new SideXDimension(this.dimension.xAxis, this.dimension.zAxis),
new SideColor(this.color.border, this.color.left),
this.border
);
// right side
sideY = new SideY(
new SideYDimension(this.dimension.yAxis, this.dimension.zAxis),
new SideColor(this.color.border, this.color.right),
this.border
);
poBrick = new PixelObject(brick);
poX = new PixelObject(sideX);
poY = new PixelObject(sideY);
ctx = this.bitmapData.context;
ctx.drawImage(poBrick.canvas, poBrick.x + this.dimension.yAxis - 2, poBrick.y);
ctx.drawImage(poX.canvas, poX.x, poX.y + this.dimension.zAxis + this.dimension.yAxis / 2 - 1);
ctx.drawImage(poY.canvas, poY.x + this.w - 2, poX.y + this.dimension.zAxis + this.dimension.xAxis / 2 - 1);
// highlight & highlight fix
bmd = new BitmapData(this.w, this.h);
if (this.border) {
offsetX = this.dimension.xAxis - 2;
offsetY = (this.dimension.xAxis + this.dimension.yAxis) / 2 - 2;
//the 2px in bounding without hightlight
for (i = 0; i < this.dimension.xAxis - 2; i += 1) {
bmd.setPixel(offsetX + 1 - i, offsetY - Math.floor(i / 2), this.color.borderHighlight);
}
//the 2px in bounding without hightlight
for (j = 0; j < this.dimension.yAxis - 2; j += 1) {
bmd.setPixel(offsetX + j, offsetY - Math.floor(j / 2), this.color.borderHighlight);
}
for (k = 0; k < this.dimension.zAxis; k += 1) {
bmd.setPixel(offsetX, offsetY + k, this.color.borderHighlight);
}
} else {
for (i = 0; i < this.dimension.zAxis; i += 1) {
bmd.setPixel(this.dimension.xAxis - 2, (this.dimension.xAxis + this.dimension.yAxis) / 2 - 1 + i, this.color.left);
}
}
bmd.context.putImageData(bmd.imageData, 0, 0);
ctx.drawImage(bmd.canvas, 0, 0);
};
// public methods
p.toString = function () {
return '[Cube]';
};
module.exports = Cube;
},{"../colors/CubeColor":2,"../colors/SideColor":5,"../dimensions/BrickDimension":8,"../dimensions/CubeDimension":9,"../dimensions/SideXDimension":14,"../dimensions/SideYDimension":15,"../display/BitmapData":17,"../display/PixelObject":18,"../geom/Matrix":20,"./AbstractPrimitive":24,"./Brick":25,"./SideX":31,"./SideY":32}],27:[function(require,module,exports){
/*jslint node: true*/
'use strict';
var LineXDimension = require('../dimensions/LineXDimension');
var LineColor = require('../colors/LineColor');
var Matrix = require('../geom/Matrix');
var BitmapData = require('../display/BitmapData');
var AbstractPrimitive = require('./AbstractPrimitive');
var LineX, p;
LineX = function (dimension, color, useDefaultCanvas) {
this.initialize(dimension, color, useDefaultCanvas);
};
p = LineX.prototype = new AbstractPrimitive();
// public properties
// constructor
p.initialize = function (dimension, color, useDefaultCanvas) {
this.initRender(dimension, color, useDefaultCanvas);
this.initRectangle();
this.initBitmapData();
this.build();
this.renderBitmapDataForCanvas();
return this;
};
// private method
p.initRender = function (dimension, color, useDefaultCanvas) {
this.useDefaultCanvas = useDefaultCanvas || false;
this.dimension = dimension === undefined ? new LineXDimension() : dimension;
this.color = color === undefined ? new LineColor() : color;
};
p.initRectangle = function () {
this.w = this.dimension.xAxis;
this.h = this.dimension.xAxis / 2;
// the matrix offset between the bitmap and the 3d pixel coordinate ZERO point
this.matrix = new Matrix();
this.matrix.tx = 0;
this.matrix.ty = 0;
};
p.initBitmapData = function () {
this.bitmapData = new BitmapData(this.w, this.h, this.useDefaultCanvas);
};
p.renderBitmapDataForCanvas = function () {
this.bitmapData.context.putImageData(this.bitmapData.imageData, 0, 0);
this.canvas = this.bitmapData.canvas;
};
p.build = function () {
var xOffsetBorder, yOffsetBorder, i, borderColor;
xOffsetBorder = 0;
yOffsetBorder = 0;
borderColor = this.color.border;
//x axis
for (i = 0; i < this.dimension.xAxis; i += 1) {
this.bitmapData.setPixel(xOffsetBorder + i, yOffsetBorder + Math.floor(i / 2), borderColor);
}
};
// public methods
p.toString = function () {
return '[LineX]';
};
module.exports = LineX;
},{"../colors/LineColor":3,"../dimensions/LineXDimension":10,"../display/BitmapData":17,"../geom/Matrix":20,"./AbstractPrimitive":24}],28:[function(require,module,exports){
/*jslint node: true*/
'use strict';
var LineYDimension = require('../dimensions/LineYDimension');
var LineColor = require('../colors/LineColor');
var Matrix = require('../geom/Matrix');
var BitmapData = require('../display/BitmapData');
var AbstractPrimitive = require('./AbstractPrimitive');
var LineY, p;
LineY = function (dimension, color, useDefaultCanvas) {
this.initialize(dimension, color, useDefaultCanvas);
};
p = LineY.prototype = new AbstractPrimitive();
// public properties
// constructor
p.initialize = function (dimension, color, useDefaultCanvas) {
this.initRender(dimension, color, useDefaultCanvas);
this.initRectangle();
this.initBitmapData();
this.build();
this.renderBitmapDataForCanvas();
return this;
};
// private method
p.initRender = function (dimension, color, useDefaultCanvas) {
this.useDefaultCanvas = useDefaultCanvas || false;
this.dimension = dimension === undefined ? new LineYDimension() : dimension;
this.color = color === undefined ? new LineColor() : color;
};
p.initRectangle = function () {
this.w = this.dimension.yAxis;
this.h = this.dimension.yAxis / 2;
// the matrix offset between the bitmap and the 3d pixel coordinate ZERO point
this.matrix = new Matrix();
this.matrix.tx = -this.dimension.yAxis + 2;
this.matrix.ty = 0;
};
p.initBitmapData = function () {
this.bitmapData = new BitmapData(this.w, this.h, this.useDefaultCanvas);
};
p.renderBitmapDataForCanvas = function () {
this.bitmapData.context.putImageData(this.bitmapData.imageData, 0, 0);
this.canvas = this.bitmapData.canvas;
};
p.build = function () {
var xOffsetBorder, yOffsetBorder, i, borderColor;
xOffsetBorder = this.dimension.yAxis - 1;
yOffsetBorder = 0;
borderColor = this.color.border;
//y axis
for (i = 0; i < this.dimension.yAxis; i += 1) {
console.log(i);
this.bitmapData.setPixel(xOffsetBorder - i, yOffsetBorder + Math.floor(i / 2), borderColor);
}
};
// public methods
p.toString = function () {
return '[LineY]';
};
module.exports = LineY;
},{"../colors/LineColor":3,"../dimensions/LineYDimension":11,"../display/BitmapData":17,"../geom/Matrix":20,"./AbstractPrimitive":24}],29:[function(require,module,exports){
/*jslint node: true*/
'use strict';
var LineZDimension = require('../dimensions/LineZDimension');
var LineColor = require('../colors/LineColor');
var Matrix = require('../geom/Matrix');
var BitmapData = require('../display/BitmapData');
var AbstractPrimitive = require('./AbstractPrimitive');
var LineZ, p;
LineZ = function (dimension, color, useDefaultCanvas) {
this.initialize(dimension, color, useDefaultCanvas);
};
p = LineZ.prototype = new AbstractPrimitive();
// public properties
// constructor
p.initialize = function (dimension, color, useDefaultCanvas) {
this.initRender(dimension, color, useDefaultCanvas);
this.initRectangle();
this.initBitmapData();
this.build();
this.renderBitmapDataForCanvas();
return this;
};
// private method
p.initRender = function (dimension, color, useDefaultCanvas) {
this.useDefaultCanvas = useDefaultCanvas || false;
this.dimension = dimension === undefined ? new LineZDimension() : dimension;
this.color = color === undefined ? new LineColor() : color;
};
p.initRectangle = function () {
this.w = 1;
this.h = this.dimension.zAxis;
// the matrix offset between the bitmap and the 3d pixel coordinate ZERO point
this.matrix = new Matrix();
this.matrix.tx = 0;
this.matrix.ty = -this.dimension.zAxis + 1;
};
p.initBitmapData = function () {
this.bitmapData = new BitmapData(this.w, this.h, this.useDefaultCanvas);
};
p.renderBitmapDataForCanvas = function () {
this.bitmapData.context.putImageData(this.bitmapData.imageData, 0, 0);
this.canvas = this.bitmapData.canvas;
};
p.build = function () {
var xOffsetBorder, yOffsetBorder, i, borderColor;
xOffsetBorder = 0;
yOffsetBorder = 0;
borderColor = this.color.border;
//y axis
for (i = 0; i < this.dimension.zAxis; i += 1) {
this.bitmapData.setPixel(xOffsetBorder, yOffsetBorder + i, borderColor);
}
};
// public methods
p.toString = function () {
return '[LineZ]';
};
module.exports = LineZ;
},{"../colors/LineColor":3,"../dimensions/LineZDimension":12,"../display/BitmapData":17,"../geom/Matrix":20,"./AbstractPrimitive":24}],30:[function(require,module,exports){
/*jslint node: true*/
'use strict';
var PyramidDimension = require('../dimensions/PyramidDimension');
var PyramidColor = require('../colors/PyramidColor');
var Matrix = require('../geom/Matrix');
var BitmapData = require('../display/BitmapData');
var AbstractPrimitive = require('./AbstractPrimitive');
var Pyramid, p;
Pyramid = function (dimension, color, border, useDefaultCanvas) {
this.initialize(dimension, color, border, useDefaultCanvas);
};
p = Pyramid.prototype = new AbstractPrimitive();
// private properties
p.hSize = null;
p.hOffset = null;
// constructor
p.initialize = function (dimension, color, border, useDefaultCanvas) {
this.initRender(dimension, color, border, useDefaultCanvas);
this.initRectangle();
this.initBitmapData();
this.build();
this.renderBitmapDataForCanvas();
return this;
};
// private method
p.initRender = function (dimension, color, border, useDefaultCanvas) {
this.useDefaultCanvas = useDefaultCanvas || false;
this.border = border || border === undefined;
this.dimension = dimension === undefined ? new PyramidDimension() : dimension;
this.color = color === undefined ? new PyramidColor() : colo