1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
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
}
};
var document = {
getElementById: function (id) {
if (id === "canvas") {
return canvas;
}
},
addEventListener: function (t, f, o) {
// ignore
}
};
var window = {
onLoad: {},
scriptTimer: {},
addEventListener: function (t, f, o) {
if (t === "load") {
this.onLoad = f;
}
},
onTimer: function () {
this.scriptTimer();
drawPolygons(context.polygonCount, context.polygonBuffer);
context.polygonCount = 0;
}
};
this.setInterval = function (f, i) {
window.scriptTimer = f;
};
// implementation of Array.map() function
// https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference:Objects:Array:map
if (!Array.prototype.map) {
Array.prototype.map = function (fun) {
var len = this.length >>> 0;
if (typeof fun !== "function") {
throw new TypeError();
}
var res = [];
var thisp = arguments[1];
for (var i = 0; i < len; i++) {
if (i in this) {
res[i] = fun.call(thisp, this[i], i, this);
}
}
return res;
};
}
|