-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphics.js
117 lines (116 loc) · 2.81 KB
/
graphics.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
114
115
116
117
define(['cclass'],function(cclass) {
return cclass({
constructor: function(context) {
this.context = context;
},
clear: function() {
this.save();
this.context.setTransform(1, 0, 0, 1, 0, 0);
this.context.clearRect(0, 0, 9000, 9000);
this.restore();
},
fillStyle: function(s) {
if (s) { this.context.fillStyle = s; }
else { return s; }
},
strokeStyle: function(s) {
if (s) { this.context.strokeStyle = s; }
else { return s; }
},
circle: function(x,y,radius) {
this.context.beginPath();
this.context.arc(x, y, radius, 0, Math.PI*2, true);
this.context.closePath();
},
rectangle: function(x,y,w,h) {
this.context.rect(x,y,w,h);
},
polygon: function(points) {
this.context.beginPath();
if (points.length > 0) {
this.context.moveTo(points[0].x,points[0].y);
for(var i=1;i<points.length;i++) {
this.context.lineTo(points[i].x,points[i].y);
}
}
this.context.closePath();
},
strokePolygon: function(points) {
this.polygon(points);
this.context.stroke();
},
fillPolygon: function(points) {
this.polygon(points);
this.context.fill();
},
strokeRectangle: function(x,y,w,h) {
this.context.strokeRect(x,y,w,h);
},
fillRectangle: function(x,y,w,h) {
this.context.fillRect(x,y,w,h);
},
strokeCircle: function(x,y,radius) {
this.circle(x,y,radius);
this.context.stroke();
},
fillCircle: function(x,y,radius) {
this.circle(x,y,radius);
this.context.fill();
},
line: function(x1,y1,x2,y2) {
this.context.beginPath();
this.context.moveTo(x1,y1);
this.context.lineTo(x2,y2);
this.context.closePath();
},
strokeLine: function(x1,y1,x2,y2) {
this.line(x1,y1,x2,y2);
this.context.stroke();
},
rotate: function(x,y,r,rotated) {
this.save();
this.context.translate(x,y);
this.context.rotate(r);
this.context.translate(-x,-y);
rotated();
this.restore();
},
scale: function(x,y,sx,sy,scaled) {
this.save();
this.context.translate(x,y);
this.context.scale(sx,sy);
this.context.translate(-x,-y);
scaled();
this.restore();
},
scalerotate: function(x,y,sx,sy,r,rotatedscaled) {
this.save();
this.context.translate(x,y);
this.context.rotate(r);
this.context.scale(sx,sy);
this.context.translate(-x,-y);
rotatedscaled();
this.restore();
},
drawImage: function(img,sx,sy,sw,sh,dx,dy,dw,dh) {
if (img) {
this.context.drawImage.apply(this.context,arguments);
}
},
drawCenteredImage: function(img,x,y) {
if (img) {
this.context.drawImage(img,x-img.width/2,y-img.height/2);
}
},
save: function() {
if (!this._depth) { this._depth = 0; }
this._depth++;
this.context.save();
},
restore: function() {
if (this._depth <= 0) { debugger; console.log('NOES'); throw "NOES"; }
this.context.restore();
this._depth--;
}
});
});