summaryrefslogtreecommitdiff
path: root/js/draw.js
blob: 09e660bb973f47d1741e8a243764346246ee88d8 (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
function draw (lex, x, y, erasing) {
	stamp (canvas, brush, x, y, erasing)
}

function line (lex, a, b, erasing) {
	var len = dist(a[0], a[1], b[0], b[1])
	var bw = 1
	var x, y, i;
	for (var i = 0; i < len; i += bw) {
		x = lerp(i / len, a[0], b[0])
		y = lerp(i / len, a[1], b[1])
		stamp (canvas, brush, x, y, erasing)
	}
}

function stamp (canvas, brush, x, y, erasing) {
	hh = brush.w/2|0
	brush.forEach(function(lex, s, t){
		s = round( s + x-hh )
		t = round( t + y-hh )
		if (lex.opacity > 0 && s >= 0 && s < canvas.w && t >= 0 && t < canvas.h) {
		  if (erasing) {
        canvas.aa[t][s].erase(lex)
		  }
		  else {
        canvas.aa[t][s].clone(lex)
		  }
		}
	})
}