A web-based drawing app
git clone git://soophie.de/outline
blob: df214c5c1cef632e5dec1c0bc794794927170dba (1305 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) {12
this.g = g;13
},14
draw: function(args) {15
let { pos, last, radius, color } = args || {};16
if(radius < 1) {17
radius = 1;18
}19
if(radius > 15) {20
radius = 15;21
}22
if(last) {23
let delta = {24
x: last.x - pos.x,25
y: last.y - pos.y26
};27
let dist = Math.sqrt(Math.pow(delta.x, 2) + Math.pow(delta.y, 2), 2);28
let length = dist / (radius / 2);29
for(let i = 0; i < length; i++) {30
let x = pos.x + (delta.x / length * i);31
let y = pos.y + (delta.y / length * i);32
this.g.fillStyle = color;33
this.g.beginPath();34
this.g.arc(x, y, 2 * radius, 0, 2 * Math.PI);35
this.g.fill();36
this.g.fillStyle = 'black';37
}38
}39
else {40
this.g.fillStyle = color;41
this.g.beginPath();42
this.g.arc(pos.x, pos.y, 2 * radius, 0, 2 * Math.PI);43
this.g.fill();44
this.g.fillStyle = 'black';45
}46
},47
roundRect: function(x, y, w, h, r) {48
if(w < 2 * r) r = w / 2;49
if(h < 2 * r) r = h / 2;50
g.beginPath();51
g.moveTo(x + r, y);52
g.arcTo(x + w, y, x + w, y + h, r);53
g.arcTo(x + w, y + h, x, y + h, r);54
g.arcTo(x, y + h, x, y, r);55
g.arcTo(x, y, x + w, y, r);56
}57
});