A web-based drawing app
git clone git://soophie.de/outline
blob: 552b715fb49c070d328fbc0bd8ba4ad3b2561b0a (1352 bytes)[doc][blame][raw]
1
function use(name, obj) {2
if(typeof module === 'object' && module && typeof module.exports === 'object') {3
module.exports = obj;4
}5
else {6
window[name] = obj;7
}8
}10
use('paint', {11
init: function(g, o) {12
this.g = g;13
this.o = o;14
},15
draw: function(args) {16
let { pos, last, radius, color } = args || {};17
if(radius < 1) {18
radius = 1;19
}20
if(radius > 15) {21
radius = 15;22
}23
if(last) {24
let delta = {25
x: last.x - pos.x,26
y: last.y - pos.y27
};28
let dist = Math.sqrt(Math.pow(delta.x, 2) + Math.pow(delta.y, 2), 2);29
let length = dist / (radius / 2);30
for(let i = 0; i < length; i++) {31
let x = pos.x + (delta.x / length * i);32
let y = pos.y + (delta.y / length * i);33
this.g.fillStyle = color;34
this.g.beginPath();35
this.g.arc(x, y, 2 * radius, 0, 2 * Math.PI);36
this.g.fill();37
this.g.fillStyle = 'black';38
}39
}40
else {41
this.g.fillStyle = color;42
this.g.beginPath();43
this.g.arc(pos.x, pos.y, 2 * radius, 0, 2 * Math.PI);44
this.g.fill();45
this.g.fillStyle = 'black';46
}47
},48
roundRect: function(x, y, w, h, r) {49
if(w < 2 * r) r = w / 2;50
if(h < 2 * r) r = h / 2;51
this.o.beginPath();52
this.o.moveTo(x + r, y);53
this.o.arcTo(x + w, y, x + w, y + h, r);54
this.o.arcTo(x + w, y + h, x, y + h, r);55
this.o.arcTo(x, y + h, x, y, r);56
this.o.arcTo(x, y, x + w, y, r);57
}58
});