-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathmagic.js
114 lines (92 loc) · 2.52 KB
/
magic.js
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
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]
];
},
state: [],
save: function () {
this.state.push(this.globalAlpha);
this.state.push(this.strokeStyle);
this.state.push(this.fillStyle);
this.globalAlpha = 1.0;
this.strokeStyle = "rgba(0, 0, 0, 1)";
this.fillStyle = "rgba(0, 0, 0, 1)";
},
restore: function () {
this.fillStyle = this.state.pop();
this.strokeStyle = this.state.pop();
this.globalAlpha = this.state.pop();
}
};
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);
};