slow Delaunay triangulation
CSS
* {
margin:0px;
padding:0px;
}
html, body {
height:100%;
overflow:hidden;
}
canvas {
width:100%;
height:100%;
outline:black 1px solid;
}
JavaScript
var rect = function (e, t) {
var n = document.createElement("canvas");
n.c = n.getContext("2d");
n.width = canvas.width;
n.height = canvas.height;
return function (r) {
n.c.clearRect(0, 0, n.width, n.height);
n.c.strokeRect(t.x * 2, t.y * 2, r.x * 2 - t.x * 2, r.y * 2 - t.y * 2);
e();
ctx.drawImage(n, 0, 0);
return rect
}
}, line = function (e, t) {
var n = document.createElement("canvas");
n.c = n.getContext("2d");
n.width = canvas.width;
n.height = canvas.height;
return function (t) {
n.c.clearRect(0, 0, n.width, n.height);
e();
ctx.drawImage(n, 0, 0);
return line
}
}, buffer = function () {
var e = document.createElement("canvas"),
t = e.getContext("2d");
e.width = screen.width * 2;
e.height = screen.height * 2;
t.drawImage(canvas, 0, 0);
var n = function () {
ctx.clearRect(0, 0, e.width, e.height);
ctx.drawImage(e, 0, 0)
};
return n
}, resizeFunction = function (e) {
var t = buffer();
canvas.width = parseFloat(getComputedStyle(canvas).width) * 2;
canvas.height = parseFloat(getComputedStyle(canvas).height) * 2;
if (e) {
t()
}
}, mousemovefunction = function (e) {
currentfunction(newPoint(e.x, e.y))
}, mouseupfunction = function (e) {
// currentfunction = currentfunction(newPoint(e.x, e.y));
// points.push(newPoint(e.x * 2, e.y * 2));
// drawpoints();
// delaunay();
window.removeEventListener("mousemove", mousemovefunction);
window.removeEventListener("mouseup", mouseupfunction)
}, mousedownfunction = function (e) {
var t = buffer();
points.push(newPoint(e.x * 2, e.y * 2));
// currentfunction = currentfunction(t, newPoint(e.x, e.y));
drawpoints();
delaunay();
window.addEventListener("mousemove", mousemovefunction);
window.addEventListener("mouseup", mouseupfunction)
},
points =...