summaryrefslogtreecommitdiff
path: root/assets/javascripts/rectangles/draw.js
blob: 278554451a5588aedb10f5a3b7691775b7c75b9e (plain)
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
function clear_canvas(){
	ctx.fillStyle = "#fff"
	ctx.fillRect(0,0,w,h)
}
function draw_ruler(){
	ctx.strokeStyle = "rgba(80,80,80,0.5)"
	ctx.lineWidth = 1
	var len = 5
	for (var i = 0.5; i < w; i += 10) {
		line(i, 0, i, len)
		line(0, i, len, i)
	}
}
function line (x,y,a,b,translation){
	if (translation) {
		x += translation.a
		a += translation.a
		y += translation.b
		b += translation.b
	}
	ctx.beginPath()
	ctx.moveTo(x,y)
	ctx.lineTo(a,b)
	ctx.stroke()
}
function draw_regions(regions){
	for (var i = 0; i < regions.length; i++) {
		if (regions[i].dupe) continue
		ctx.fillStyle = colors[i % colors.length]
		regions[i].fill().stroke_sides()
	}
}
function draw_mouse(mouse){
	ctx.fillStyle = "rgba(255,0,0,0.4)";
	ctx.beginPath();
	ctx.arc(mouse.x.b, mouse.y.b, 5, 0, 2*Math.PI, false);
	ctx.fill();

	if (mouse.width() != 0 && mouse.height() != 0) {
		if (app.dragging) {
			mouse.stroke()
		}
		else {
			ctx.fillStyle = "rgba(255,255,0,0.5)"
			mouse.clone().normalize().fill()
		}
	}
}