A web-based drawing app
git clone git://soophie.de/outline
blob: 48918a65df350634bccd40b0f9db9cdf8b2bd1c8 (805 bytes)[doc][blame][raw]
1
module.exports = {2
init: function(g, o) {3
this.g = g;4
this.o = o;5
},6
draw: function(args) {7
let { pos, last, radius, color } = args || {};8
if(last) {9
let delta = {10
x: last.x - pos.x,11
y: last.y - pos.y12
};13
let dist = Math.sqrt(Math.pow(delta.x, 2) + Math.pow(delta.y, 2), 2);14
let length = dist / (radius / 2);15
for(let i = 0; i < length; i++) {16
let x = pos.x + (delta.x / length * i);17
let y = pos.y + (delta.y / length * i);18
this.g.fillStyle = color;19
this.g.beginPath();20
this.g.arc(x, y, 2 * radius, 0, 2 * Math.PI);21
this.g.fill();22
this.g.fillStyle = 'black';23
}24
}25
else {26
this.g.fillStyle = color;27
this.g.beginPath();28
this.g.arc(pos.x, pos.y, 2 * radius, 0, 2 * Math.PI);29
this.g.fill();30
this.g.fillStyle = 'black';31
}32
}33
};