-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrawable.js
47 lines (39 loc) · 1.06 KB
/
drawable.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
TS.Drawable = Class.create(TS, {
initialize: function (container, options) {
this.container = container;
this.position = Object.extend({
x: 0,
y: 0
}, options.position || {});
this.size = Object.extend({
width: 1,
height: 1
}, options.size || {});
this.translate = options.translate;
},
getRelativePosition: function (position) {
var pos = {
x: position.x - this.translate.x,
y: position.y - this.translate.y
};
pos.x = (pos.x / this.size.width) * 100;
pos.y = (pos.y / this.size.height) * 100;
return pos;
},
getAbsolutePosition: function (position) {
var pos = {
x: position.x / 100 * this.size.width,
y: position.y / 100 * this.size.height
};
pos.x += this.translate.x;
pos.y += this.translate.y;
return pos;
},
getQuadraticCurvePoint: function (from, to, ratio) {
var x = {
x: (from.x + (to.x - from.x) / 2 + (to.y - from.y) * ratio),
y: (from.y + (to.y - from.y) / 2 + (to.x - from.x) * ratio * -1)
};
return x;
},
});