-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjoy.tis
61 lines (44 loc) · 1.39 KB
/
joy.tis
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
// joy demo
include "lib/decorators.tis";
include "lib/log.tis";
@change @on "#move-v, #move-h" :: move_cross();
@change @on "#move-r" :: move_angle();
function move_cross() {
var mx = $(#move-h).value,
my = $(#move-v).value;
// bounding rectangle
var (x,y,w,h) = $(#square).box(#rectw, #inner, #view);
// translate coords
var px = mx*w/100 + x, py = my*h/100 + y;
var img = $(#cross);
(w,h) = img.box(#dimension, #inner);
img.move(px - w/2, py - w/2);
}
function move_angle() {
var angle = $(#move-r).value;
var img = $(#angle);
img.style["transform"] = String.printf("rotate(%ddeg)", angle);
// bounding rectangle
var (x,y,w,h) = $(#circle).box(#rectw, #inner, #view);
var cx = x + w/2, cy = y + h/2;
var radius = w/2 - 10;
// sin(a) = y/r y = sin(a)*r
// cos(a) = x/r x = cos(a)*r
angle = (90+angle) * Math.PI / 180;
var px = Math.cos(angle) * radius,
py = Math.sin(angle) * radius;
(w,h) = img.box(#dimension, #inner);
img.move(px.toInteger() + cx - w/2, py.toInteger() + cy - h/2);
}
$(#circle > .area).paintOutline = function(dc) {
var area = $(#circle > .area);
var (x,y,w,h) = area.box(#rectw, #inner, #view);
var cx = x + w/2, cy = y + h/2;
var radius = w/2 - 10;
dc.save();
dc.lineColor(color(80,139,106));
dc.lineWidth(2);
// dc.arc(40,15,radius,radius,0,360);
dc.restore();
return false;
}