summaryrefslogtreecommitdiffstats
path: root/webmonster/magic.js
diff options
context:
space:
mode:
authorAriya Hidayat <ariya.hidayat@nokia.com>2009-04-06 15:56:42 +0200
committerAriya Hidayat <ariya.hidayat@nokia.com>2009-04-06 15:56:42 +0200
commita37422434e2140ccb606f166238f75a5a741ec03 (patch)
treeb6e1ab5e54bb9ad3bdfd85cfe68e408ac0d40f91 /webmonster/magic.js
parentfe7337a822df126ad661c5cfa21cfe0c20a80390 (diff)
Part 2 of the Monster series
Diffstat (limited to 'webmonster/magic.js')
-rw-r--r--webmonster/magic.js96
1 files changed, 96 insertions, 0 deletions
diff --git a/webmonster/magic.js b/webmonster/magic.js
new file mode 100644
index 0000000..056df11
--- /dev/null
+++ b/webmonster/magic.js
@@ -0,0 +1,96 @@
+
+var context = {
+ width: 800,
+ height: 600,
+ globalAlpha: 1.0,
+ strokeStyle: "rgba(0, 0, 0, 1)",
+ fillStyle: "rgba(0, 0, 0, 1)",
+ pointCount: 0,
+ pointArray: [0, 0, 0, 0, 0, 0, 0, 0],
+ polygonCount: 0,
+ polygonBuffer: [],
+
+ beginPath: function () {
+ this.pointCount = 0;
+ },
+
+ moveTo: function (x, y) {
+ this.pointArray[this.pointCount++] = x;
+ this.pointArray[this.pointCount++] = y;
+ },
+
+ lineTo: function (x, y) {
+ this.pointArray[this.pointCount++] = x;
+ this.pointArray[this.pointCount++] = y;
+ },
+
+ closePath: function () {
+ // ignore
+ },
+
+ stroke: function () {
+ this.polygonBuffer[this.polygonCount++] = [
+ this.globalAlpha, this.strokeStyle, "none",
+ this.pointCount, this.pointArray.slice()
+ ];
+ },
+
+ fill: function () {
+ this.polygonBuffer[this.polygonCount++] = [
+ this.globalAlpha, "none", this.fillStyle,
+ this.pointCount, this.pointArray.slice()
+ ];
+ },
+
+ fillRect: function (x, y, w, h) {
+ this.polygonBuffer[this.polygonCount++] = [
+ 1.0, "none", this.fillStyle,
+ this.pointCount, [x, y, x + w, y, x + w, y + h, x, y + h]
+ ];
+ }
+};
+
+var canvas = {
+ width: 800,
+ height: 600,
+
+ getContext: function (id) {
+ if (id === "2d") {
+ return context;
+ }
+ },
+
+ addEventListener: function (t, f, o) {
+ // ignore
+ }
+};
+
+document.getElementById = function (id) {
+ if (id === "canvas") {
+ return canvas;
+ }
+};
+
+document.addEventListener = function(t, f, o) {
+ // ignore
+};
+
+window.addEventListener = function (t, f, o) {
+ if (t === "load") {
+ this.onLoad = f;
+ }
+};
+
+window.onTimer = function() {
+ this.scriptTimer();
+ window.webmonster.drawPolygons(context.polygonCount, context.polygonBuffer);
+ context.polygonCount = 0;
+};
+
+window.originalSetInterval = window.setInterval;
+
+this.setInterval = function(f, i) {
+ window.scriptTimer = f;
+ this.originalSetInterval(window.onTimer, i);
+};
+