-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdrawer.js
104 lines (86 loc) · 2.73 KB
/
drawer.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
var lastRedraw = new Date().getTime();
redraw = function(){
var time = new Date().getTime();
var fps = 1000/(time-lastRedraw);
var tps = fps*model.tickCount;
model.tickCount = 0;
lastRedraw = time;
ctx.putImageData(img, 0, 0);
// items
ctx.strokeStyle = "rgba(100, 100, 150, 1)";
for(var i=0; i<model.pool.length; i++)
if(model.pool[i].shape instanceof Polyline2D)
drawPolyline(model.pool[i].shape);
// GUI
ctx.fillStyle = "rgba(100, 100, 100, 0.5)";
if(model.aimed)
drawDisc(new Circle(model.aimed.coord, 20))
ctx.fillStyle = "rgba(150, 100, 100, 0.5)";
if(model.selected)
drawDisc(new Circle(model.selected.coord, 20))
ctx.fillStyle = "rgba(255, 255, 255, 1)";
ctx.font="11px Verdana";
ctx.fillText("fps : "+parseInt(fps),10,300);
ctx.fillText("tps : "+parseInt(tps),10,315);
ctx.fillText("rays : "+model.rayCount,10,330);
setTimeout(redraw, 30);
};
updateGUI = function(){
if(model.selected){
if(model.selected.type == "light"){
$(".lightpanel").show();
$(".surfacepanel").hide();
var s = model.selected;
$(".in_arc, .ran_arc").val(s.arc);
$(".in_size, .ran_size").val(s.size);
} else {
$(".lightpanel").hide();
$(".surfacepanel").show();
var s = model.getCurrentSurface();
if(s.ref>0)
$(".inside_refraction_cursors").css('visibility', 'visible');
else
$(".inside_refraction_cursors").css('visibility', 'hidden');
$(".in_specular, .ran_specular").val(s.spec);
$(".in_diffusion, .ran_diffusion").val(s.diff);
$(".in_refraction, .ran_refraction").val(s.ref);
$(".in_minRef, .ran_minRef").val(s.minRef);
$(".in_maxRef, .ran_maxRef").val(s.maxRef);
}
} else {
$(".lightpanel").hide();
$(".surfacepanel").hide();
}
};
/* Drawing functions
*/
drawPoint = function(p, stroke){
var c1 = p.getSub(stroke);
var c2 = p.getAdd(stroke);
ctx.fillRect(c1.x, c1.y, stroke*2, stroke*2);
}
drawPolyline = function(pl){
for(var i=0; i<pl.lines.length; i++)
drawLine(pl.lines[i]);
}
drawLine = function(l) {
l = l.toFinite();
ctx.beginPath();
ctx.moveTo(l.start().x, l.start().y);
ctx.lineTo(l.end().x, l.end().y);
ctx.lineWidth = 1;
ctx.stroke();
ctx.closePath();
}
drawCircle = function(c){
ctx.beginPath();
ctx.arc(c.center.x, c.center.y, c.radius, 0, Angle.FULL);
ctx.stroke();
ctx.closePath();
}
drawDisc = function(c){
ctx.beginPath();
ctx.arc(c.center.x, c.center.y, c.radius, 0, Angle.FULL);
ctx.fill();
ctx.closePath();
}