Matrix.js
2.08 KB
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
function radianToDegree(angle) { return angle * (180.0 / Math.PI); }
function degreeToRadian(angle) { return Math.PI * angle / 180.0; }
function Matrix(a, b, c, d, tx, ty) {
this.elements = [a||1, c||0, tx||0,
b||0, d||1, ty||0];
this.__defineGetter__("a", function() { return this.elements[0]; });
this.__defineSetter__("a", function(n) { this.elements[0]=n; });
this.__defineGetter__("b", function() { return this.elements[3]; });
this.__defineSetter__("b", function(n) { this.elements[3]=n; });
this.__defineGetter__("c", function() { return this.elements[1]; });
this.__defineSetter__("c", function(n) { this.elements[1]=n; });
this.__defineGetter__("d", function() { return this.elements[4]; });
this.__defineSetter__("d", function(n) { this.elements[4]=n; });
this.__defineGetter__("tx", function() { return this.elements[2]; });
this.__defineSetter__("tx", function(n) { this.elements[2]=n; });
this.__defineGetter__("ty", function() { return this.elements[5]; });
this.__defineSetter__("ty", function(n) { this.elements[5]=n; });
this.clone = function() {
};
this.concat = function(m) {
};
this.identity = function() {
this.elements = [1, 0, 0, 1, 0, 0];
};
this.scale = function(sx, sy) {
if (sx && !sy) {
sy = sx;
}
if (sx && sy) {
this.elements[0] *= sx;
this.elements[1] *= sy;
this.elements[3] *= sx;
this.elements[4] *= sy;
}
};
this.translate = function(dx, dy) {
this.elements[2] = dx * this.elements[0] + dy * this.elements[1] + this.elements[2];
this.elements[5] = dx * this.elements[3] + dy * this.elements[4] + this.elements[5];
};
this.angle = 0; // faster but dumber method
this.rotate = function(angle) {
this.angle += angle;
r = radianToDegree(angle);
c = Math.cos(angle);
s = Math.sin(angle);
temp1 = this.elements[0];
temp2 = this.elements[1];
this.elements[0] = c * temp1 + s * temp2;
this.elements[1] = -s * temp1 + c * temp2;
temp1 = this.elements[3];
temp2 = this.elements[4];
this.elements[3] = c * temp1 + s * temp2;
this.elements[4] = -s * temp1 + c * temp2;
};
}