Slow Delaunay triangulation

Size
3,316 Kb
Views
30,360

How do I make an slow delaunay triangulation?

What is a slow delaunay triangulation? How do you make a slow delaunay triangulation? This script and codes were developed by Darby Rathbone on 03 October 2022, Monday.

Slow Delaunay triangulation Previews

Slow Delaunay triangulation - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>slow Delaunay triangulation</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <canvas></canvas> <script src="js/index.js"></script>
</body>
</html>

Slow Delaunay triangulation - Script Codes CSS Codes

* { margin:0px; padding:0px;
}
html, body { height:100%; overflow:hidden;
}
canvas { width:100%; height:100%; outline:black 1px solid;
}

Slow Delaunay triangulation - Script Codes JS Codes

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 }
}, bufferd = document.createElement("canvas");
bufferd.width = screen.width * 2;
bufferd.height = screen.height * 2;
var buffer = function () { t = bufferd.getContext("2d"); t.drawImage(ctx.canvas, 0, 0); var n = function () { ctx.clearRect(0, 0, bufferd.width, bufferd.height); ctx.drawImage(bufferd, 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(), _point = newPoint(e.x * 2, e.y * 2); if (!points.some(function (b) { var d = Math.sqrt((b.x - _point.x) * (b.x - _point.x) + (b.y - _point.y) * (b.y - _point.y)); return d < 10; })) { points.push(_point); // currentfunction = currentfunction(t, newPoint(e.x, e.y)); drawpoints(); delaunay(); window.addEventListener("mousemove", mousemovefunction); window.addEventListener("mouseup", mouseupfunction) }
},
points = [];
window.addEventListener("mousedown", mousedownfunction);
window.addEventListener("resize", resizeFunction);
var newPoint = function (e, t) { var n = Object.create(null); n.x = e; n.y = t; n.connected = []; n.mult = function (e) { return newPoint(n.x * e, n.y * e) }; n.add = function (e) { return newPoint(n.x + e.x, n.y + e.y) }; n.clone = function () { return newPoint(n.x, n.y) }; return n
},
newLine = function (e) { var t = Object.create(null); t.p1 = e; t.point = function (e) { this.p2 = e; this.slope = (e.y - this.p1.y) / (e.x - this.p1.x); this.dx = e.x - this.p1.x; this.dy = e.y - this.p1.y; return this }; t.setSlope = function (e, t, n) { this.slope = e; if (isFinite(e)) { this.dx = 1; this.dy = this.slope } else { this.dx = t; this.dy = n } }; t.getB = function () { this.xint = this.xint || this.p1.y - this.p1.x * this.slope; return this.xint }; t.int = function (e) { var t = (e.getB() - this.getB()) / ((e.dx * this.dy - this.dx * e.dy) / this.dx * e.dx); return newPoint(t, t * this.slope + this.getB()) }; t.draw = function (e) { this.xint = this.p1.y - this.p1.x * this.slope; e.beginPath(); e.moveTo(0, this.xint); e.lineTo(Math.max(e.canvas.width, e.canvas.height), Math.max(e.canvas.width, e.canvas.height) * this.slope + this.xint); e.stroke() }; return Object.create(t)
}, delaunay = (function () { var exe = [], _delaunay = function () { var _points = points.slice(), newpoints = _points.filter(function (e) { return e.connected.length == 0 }), rand1 = Math.random(), rand2 = Math.random(); for (var count3 = 0, e = newpoints[count3]; e; e = newpoints[++count3]) { for (var count1 = 0, t = _points[count1]; t; t = _points[++count1]) { var n = newLine(e.clone().add(t).mult(.5)); n.setSlope((t.x + rand1 - e.x + rand2) / (e.y + rand1 - t.y + rand2)); for (var count2 = count1, r = _points[count2]; r; r = _points[++count2]) { if (r !== e && r !== t && e !== t) { var i = newLine(r.clone().add(t).mult(.5)); i.setSlope((t.x + rand1 - r.x + rand2) / (r.y + rand1 - t.y + rand2)); var s = n.int(i); var o = Math.sqrt((s.x - r.x) * (s.x - r.x) + (s.y - r.y) * (s.y - r.y)); ctx.strokeStyle = 'rgba(0,0,0,1)'; ctx.beginPath(); ctx.arc(s.x, s.y, o, 0, 2 * Math.PI, false); var u = _points.filter(function (n) { return n !== e && n !== t && n !== r }).filter(function (e) { var z = ctx.isPointInPath(e.x, e.y); return z }); if (u.length === 0) { ctx.save(); ctx.beginPath(); ctx.moveTo(e.x, e.y); ctx.lineTo(t.x, t.y); ctx.lineTo(r.x, r.y); ctx.lineTo(e.x, e.y); e.connected ctx.closePath(false); ctx.clip(); ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.restore(); ctx.stroke(); ctx.beginPath(); ctx.arc(s.x, s.y, 5, 0, 2 * Math.PI, false); ctx.strokeStyle = 'rgba(255,0,0,1)'; ctx.stroke(); e.connected.push(t, r); t.connected.push(e, r); r.connected.push(e, t) } } } }; drawpoints(); if (exe.length !== 0) (exe.shift()); } }; return function () { exe.push( _delaunay()); if (exe.length === 1)(exe.shift()); }
}()), drawpoints = function () { points.forEach(function (e) { ctx.beginPath(); ctx.arc(e.x | 0, e.y | 0, 5, 0, 2 * Math.PI, false); ctx.fill(); ctx.stroke() }); bufferd.getContext('2d').clearRect(0, 0, canvas.width, canvas.height); bufferd.getContext("2d").drawImage(canvas, 0, 0, canvas.width, canvas.height, 0, 0, canvas.width, canvas.height); }, canvas = document.getElementsByTagName("canvas")[0], ctx = canvas.getContext("2d"), currentfunction = delaunay;
resizeFunction();
ctx.strokeStyle = "RGBA(0,0,0,1)";
ctx.fillStyle = "RGBA(255,255,255,.25)";
ctx.font = ctx.font.replace(ctx.font.split(" ")[0], "42px")
Slow Delaunay triangulation - Script Codes
Slow Delaunay triangulation - Script Codes
Home Page Home
Developer Darby Rathbone
Username blackkbot
Uploaded October 03, 2022
Rating 3
Size 3,316 Kb
Views 30,360
Do you need developer help for Slow Delaunay triangulation?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Darby Rathbone (blackkbot) Script Codes
Create amazing captions with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!