Toggle navigation
Sign Up
Log In
Explore
Works
Folders
Tools
Collections
Artists
Groups
Groups
Topics
Tasks
Tasks
Jobs
Teams
Jobs
Recommendation
More Effects...
JS
// sorry about minified JS! // almost all of the lloyd's algorithm shamelessly lifted from raymond hill's site, and converted to functional style // code is here: https://github.com/dazld/recursive-subdivision/blob/master/assets/js/index.js ! function e(t, r, i) { function n(s, h) { if (!r[s]) { if (!t[s]) { var a = "function" == typeof require && require; if (!h && a) return a(s, !0); if (o) return o(s, !0); var l = new Error("Cannot find module '" + s + "'"); throw l.code = "MODULE_NOT_FOUND", l } var c = r[s] = { exports: {} }; t[s][0].call(c.exports, function(e) { var r = t[s][1][e]; return n(r ? r : e) }, c, c.exports, e, t, r, i) } return r[s].exports } for (var o = "function" == typeof require && require, s = 0; s < i.length; s++) n(i[s]); return n }({ 1: [function(e, t, r) { "use strict"; function i(e) { return e && e.__esModule ? e : { "default": e } } function n(e, t) { b.ctx.globalAlpha = 1, b.ctx.lineWidth = .2, e.cells.forEach(function(e) { if (e.halfedges.length < 3) return void console.log("skip"); b.ctx.beginPath(), b.ctx.fillStyle = "rgb(" + e.site.depth / y * 192 + ",32,32)"; var t = e.halfedges[0].getStartpoint(); b.ctx.moveTo(t.x, t.y), e.halfedges.forEach(function(e) { var t = e.getEndpoint(); b.ctx.lineTo(t.x, t.y) }), b.ctx.closePath(), b.ctx.fill() }) } function o() { return Math.random() > .5 } function s(e, t, r) { var i = arguments.length <= 3 || void 0 === arguments[3] ? 1 : arguments[3], n = o(), h = r / 2; if (n && r > 4) { var a = i + 1; s(e, t, h, a), s(e + h, t, h, a), s(e, t + h, h, a), s(e + h, t + h, h, a) } else i > y && (y = i), g.push({ x: e + h, y: t + h, depth: i }) } function h() { g = []; for (var e = 0; e < c["default"].width; e += x) for (var t = 0; t < c["default"].height; t += x) s(e, t, x, 1); diagram = p.compute(g, v) } function a() { var e = void 0; try { if (E) throw E = !1, "restarting"; e = (0, u.relaxSites)(diagram), R.length && e.push(R.pop()), diagram = p.compute(e, v), b.ctx.clearRect(0, 0, window.innerWidth, window.innerHeight), n(diagram, e), requestAnimationFrame(a) } catch (t) { console.log(t), h(), requestAnimationFrame(a) } } var l = e("./lib/window-size"), c = i(l), f = e("voronoi"), d = i(f), u = e("./lib/relax"), b = e("./lib/frame"); window.ctx = b.ctx; var p = new d["default"], v = { xl: -1, xr: window.innerWidth + 1, yt: -1, yb: window.innerHeight + 1 }, g = [], y = 0; console.log(y); var x = 512; window.diagram = null, h(); var R = [], E = !1; a(), setInterval(function() { E = !0 }, 5e3), b.canvas.addEventListener("click", function(e) { E = !0 }) }, { "./lib/frame": 2, "./lib/relax": 3, "./lib/window-size": 4, voronoi: 5 }], 2: [function(e, t, r) { "use strict"; function i(e) { return e && e.__esModule ? e : { "default": e } } Object.defineProperty(r, "__esModule", { value: !0 }), r.ctx = r.canvas = void 0; var n = e("./window-size"), o = i(n), s = r.canvas = document.createElement("canvas"); document.body.appendChild(s), s.height = window.innerHeight, s.width = window.innerWidth, s.style.width = o["default"].wpx, s.style.height = o["default"].hpx; var h = r.ctx = s.getContext("2d"), a = window.devicePixelRatio || 1, l = h.webkitBackingStorePixelRatio || h.mozBackingStorePixelRatio || h.msBackingStorePixelRatio || h.oBackingStorePixelRatio || h.backingStorePixelRatio || 1, c = a / l; if (a !== l) { var f = s.width, d = s.height; s.width = f * c, s.height = d * c, s.style.width = f + "px", s.style.height = d + "px", h.scale(c, c) } }, { "./window-size": 4 }], 3: [function(e, t, r) { "use strict"; function i(e, t) { var r = e.x - t.x, i = e.y - t.y; return Math.sqrt(r * r + i * i) } function n(e) { for (var t = 0, r = e.halfedges, i = r.length, n = void 0, o = void 0, s = void 0; i--;) n = r[i], o = n.getStartpoint(), s = n.getEndpoint(), t += o.x * s.y, t -= o.y * s.x; return t /= 2 } function o(e) { var t = 0, r = 0, i = e.halfedges, o = i.length; if (0 === o) return { x: e.site.x, y: e.site.y }; for (var s = void 0, h = void 0, a = void 0, l = void 0; o--;) s = i[o], a = s.getStartpoint(), l = s.getEndpoint(), h = a.x * l.y - l.x * a.y, t += (a.x + l.x) * h, r += (a.y + l.y) * h; var c = 6 * n(e); return { x: t / c, y: r / c, depth: e.site.depth, area: Math.abs(c) } } function s(e) { for (var t = e.cells, r = [], n = t.length, s = 1 / n * .1; n--;) { var h = t[n], a = Math.random(); if (!(a < s)) { var l = o(h), c = i(l, h.site); if (c) { if (c > 2 && (l.x = (l.x + h.site.x) / 2, l.y = (l.y + h.site.y) / 2), a > 1 - s) { c /= 2; var f = { x: l.x + (l.x - h.site.x) / c, y: l.y + (l.y - h.site.y) / c, depth: h.site.depth }; r.push(f) } r.push(l) } } } return r } Object.defineProperty(r, "__esModule", { value: !0 }), r.relaxSites = s }, {}], 4: [function(e, t, r) { "use strict"; function i(e) { return e + "px" } Object.defineProperty(r, "__esModule", { value: !0 }), r.wrapInPx = i; var n = { width: window.innerWidth, height: window.innerHeight, get wpx() { return i(this.width) }, get hpx() { return i(this.height) } }; window.addEventListener("resize", function() { n.width = window.innerWidth, n.height = window.innerHeight }), r["default"] = n }, {}], 5: [function(e, t, r) { function i() { this.vertices = null, this.edges = null, this.cells = null, this.toRecycle = null, this.beachsectionJunkyard = [], this.circleEventJunkyard = [], this.vertexJunkyard = [], this.edgeJunkyard = [], this.cellJunkyard = [] } i.prototype.reset = function() { if (this.beachline || (this.beachline = new this.RBTree), this.beachline.root) for (var e = this.beachline.getFirst(this.beachline.root); e;) this.beachsectionJunkyard.push(e), e = e.rbNext; this.beachline.root = null, this.circleEvents || (this.circleEvents = new this.RBTree), this.circleEvents.root = this.firstCircleEvent = null, this.vertices = [], this.edges = [], this.cells = [] }, i.prototype.sqrt = Math.sqrt, i.prototype.abs = Math.abs, i.prototype.ε = i.ε = 1e-9, i.prototype.invε = i.invε = 1 / i.ε, i.prototype.equalWithEpsilon = function(e, t) { return this.abs(e - t) < 1e-9 }, i.prototype.greaterThanWithEpsilon = function(e, t) { return e - t > 1e-9 }, i.prototype.greaterThanOrEqualWithEpsilon = function(e, t) { return t - e < 1e-9 }, i.prototype.lessThanWithEpsilon = function(e, t) { return t - e > 1e-9 }, i.prototype.lessThanOrEqualWithEpsilon = function(e, t) { return e - t < 1e-9 }, i.prototype.RBTree = function() { this.root = null }, i.prototype.RBTree.prototype.rbInsertSuccessor = function(e, t) { var r; if (e) { if (t.rbPrevious = e, t.rbNext = e.rbNext, e.rbNext && (e.rbNext.rbPrevious = t), e.rbNext = t, e.rbRight) { for (e = e.rbRight; e.rbLeft;) e = e.rbLeft; e.rbLeft = t } else e.rbRight = t; r = e } else this.root ? (e = this.getFirst(this.root), t.rbPrevious = null, t.rbNext = e, e.rbPrevious = t, e.rbLeft = t, r = e) : (t.rbPrevious = t.rbNext = null, this.root = t, r = null); t.rbLeft = t.rbRight = null, t.rbParent = r, t.rbRed = !0; var i, n; for (e = t; r && r.rbRed;) i = r.rbParent, r === i.rbLeft ? (n = i.rbRight, n && n.rbRed ? (r.rbRed = n.rbRed = !1, i.rbRed = !0, e = i) : (e === r.rbRight && (this.rbRotateLeft(r), e = r, r = e.rbParent), r.rbRed = !1, i.rbRed = !0, this.rbRotateRight(i))) : (n = i.rbLeft, n && n.rbRed ? (r.rbRed = n.rbRed = !1, i.rbRed = !0, e = i) : (e === r.rbLeft && (this.rbRotateRight(r), e = r, r = e.rbParent), r.rbRed = !1, i.rbRed = !0, this.rbRotateLeft(i))), r = e.rbParent; this.root.rbRed = !1 }, i.prototype.RBTree.prototype.rbRemoveNode = function(e) { e.rbNext && (e.rbNext.rbPrevious = e.rbPrevious), e.rbPrevious && (e.rbPrevious.rbNext = e.rbNext), e.rbNext = e.rbPrevious = null; var t, r = e.rbParent, i = e.rbLeft, n = e.rbRight; t = i ? n ? this.getFirst(n) : i : n, r ? r.rbLeft === e ? r.rbLeft = t : r.rbRight = t : this.root = t; var o; if (i && n ? (o = t.rbRed, t.rbRed = e.rbRed, t.rbLeft = i, i.rbParent = t, t !== n ? (r = t.rbParent, t.rbParent = e.rbParent, e = t.rbRight, r.rbLeft = e, t.rbRight = n, n.rbParent = t) : (t.rbParent = r, r = t, e = t.rbRight)) : (o = e.rbRed, e = t), e && (e.rbParent = r), !o) { if (e && e.rbRed) return void(e.rbRed = !1); var s; do { if (e === this.root) break; if (e === r.rbLeft) { if (s = r.rbRight, s.rbRed && (s.rbRed = !1, r.rbRed = !0, this.rbRotateLeft(r), s = r.rbRight), s.rbLeft && s.rbLeft.rbRed || s.rbRight && s.rbRight.rbRed) { s.rbRight && s.rbRight.rbRed || (s.rbLeft.rbRed = !1, s.rbRed = !0, this.rbRotateRight(s), s = r.rbRight), s.rbRed = r.rbRed, r.rbRed = s.rbRight.rbRed = !1, this.rbRotateLeft(r), e = this.root; break } } else if (s = r.rbLeft, s.rbRed && (s.rbRed = !1, r.rbRed = !0, this.rbRotateRight(r), s = r.rbLeft), s.rbLeft && s.rbLeft.rbRed || s.rbRight && s.rbRight.rbRed) { s.rbLeft && s.rbLeft.rbRed || (s.rbRight.rbRed = !1, s.rbRed = !0, this.rbRotateLeft(s), s = r.rbLeft), s.rbRed = r.rbRed, r.rbRed = s.rbLeft.rbRed = !1, this.rbRotateRight(r), e = this.root; break } s.rbRed = !0, e = r, r = r.rbParent } while (!e.rbRed); e && (e.rbRed = !1) } }, i.prototype.RBTree.prototype.rbRotateLeft = function(e) { var t = e, r = e.rbRight, i = t.rbParent; i ? i.rbLeft === t ? i.rbLeft = r : i.rbRight = r : this.root = r, r.rbParent = i, t.rbParent = r, t.rbRight = r.rbLeft, t.rbRight && (t.rbRight.rbParent = t), r.rbLeft = t }, i.prototype.RBTree.prototype.rbRotateRight = function(e) { var t = e, r = e.rbLeft, i = t.rbParent; i ? i.rbLeft === t ? i.rbLeft = r : i.rbRight = r : this.root = r, r.rbParent = i, t.rbParent = r, t.rbLeft = r.rbRight, t.rbLeft && (t.rbLeft.rbParent = t), r.rbRight = t }, i.prototype.RBTree.prototype.getFirst = function(e) { for (; e.rbLeft;) e = e.rbLeft; return e }, i.prototype.RBTree.prototype.getLast = function(e) { for (; e.rbRight;) e = e.rbRight; return e }, i.prototype.Diagram = function(e) { this.site = e }, i.prototype.Cell = function(e) { this.site = e, this.halfedges = [], this.closeMe = !1 }, i.prototype.Cell.prototype.init = function(e) { return this.site = e, this.halfedges = [], this.closeMe = !1, this }, i.prototype.createCell = function(e) { var t = this.cellJunkyard.pop(); return t ? t.init(e) : new this.Cell(e) }, i.prototype.Cell.prototype.prepareHalfedges = function() { for (var e, t = this.halfedges, r = t.length; r--;) e = t[r].edge, e.vb && e.va || t.splice(r, 1); return t.sort(function(e, t) { return t.angle - e.angle }), t.length }, i.prototype.Cell.prototype.getNeighborIds = function() { for (var e, t = [], r = this.halfedges.length; r--;) e = this.halfedges[r].edge, null !== e.lSite && e.lSite.voronoiId != this.site.voronoiId ? t.push(e.lSite.voronoiId) : null !== e.rSite && e.rSite.voronoiId != this.site.voronoiId && t.push(e.rSite.voronoiId); return t }, i.prototype.Cell.prototype.getBbox = function() { for (var e, t, r, i = this.halfedges, n = i.length, o = 1 / 0, s = 1 / 0, h = -(1 / 0), a = -(1 / 0); n--;) e = i[n].getStartpoint(), t = e.x, r = e.y, t < o && (o = t), r < s && (s = r), t > h && (h = t), r > a && (a = r); return { x: o, y: s, width: h - o, height: a - s } }, i.prototype.Cell.prototype.pointIntersection = function(e, t) { for (var r, i, n, o, s = this.halfedges, h = s.length; h--;) { if (r = s[h], i = r.getStartpoint(), n = r.getEndpoint(), o = (t - i.y) * (n.x - i.x) - (e - i.x) * (n.y - i.y), !o) return 0; if (o > 0) return -1 } return 1 }, i.prototype.Vertex = function(e, t) { this.x = e, this.y = t }, i.prototype.Edge = function(e, t) { this.lSite = e, this.rSite = t, this.va = this.vb = null }, i.prototype.Halfedge = function(e, t, r) { if (this.site = t, this.edge = e, r) this.angle = Math.atan2(r.y - t.y, r.x - t.x); else { var i = e.va, n = e.vb; this.angle = e.lSite === t ? Math.atan2(n.x - i.x, i.y - n.y) : Math.atan2(i.x - n.x, n.y - i.y) } }, i.prototype.createHalfedge = function(e, t, r) { return new this.Halfedge(e, t, r) }, i.prototype.Halfedge.prototype.getStartpoint = function() { return this.edge.lSite === this.site ? this.edge.va : this.edge.vb }, i.prototype.Halfedge.prototype.getEndpoint = function() { return this.edge.lSite === this.site ? this.edge.vb : this.edge.va }, i.prototype.createVertex = function(e, t) { var r = this.vertexJunkyard.pop(); return r ? (r.x = e, r.y = t) : r = new this.Vertex(e, t), this.vertices.push(r), r }, i.prototype.createEdge = function(e, t, r, i) { var n = this.edgeJunkyard.pop(); return n ? (n.lSite = e, n.rSite = t, n.va = n.vb = null) : n = new this.Edge(e, t), this.edges.push(n), r && this.setEdgeStartpoint(n, e, t, r), i && this.setEdgeEndpoint(n, e, t, i), this.cells[e.voronoiId].halfedges.push(this.createHalfedge(n, e, t)), this.cells[t.voronoiId].halfedges.push(this.createHalfedge(n, t, e)), n }, i.prototype.createBorderEdge = function(e, t, r) { var i = this.edgeJunkyard.pop(); return i ? (i.lSite = e, i.rSite = null) : i = new this.Edge(e, null), i.va = t, i.vb = r, this.edges.push(i), i }, i.prototype.setEdgeStartpoint = function(e, t, r, i) { e.va || e.vb ? e.lSite === r ? e.vb = i : e.va = i : (e.va = i, e.lSite = t, e.rSite = r) }, i.prototype.setEdgeEndpoint = function(e, t, r, i) { this.setEdgeStartpoint(e, r, t, i) }, i.prototype.Beachsection = function() {}, i.prototype.createBeachsection = function(e) { var t = this.beachsectionJunkyard.pop(); return t || (t = new this.Beachsection), t.site = e, t }, i.prototype.leftBreakPoint = function(e, t) { var r = e.site, i = r.x, n = r.y, o = n - t; if (!o) return i; var s = e.rbPrevious; if (!s) return -(1 / 0); r = s.site; var h = r.x, a = r.y, l = a - t; if (!l) return h; var c = h - i, f = 1 / o - 1 / l, d = c / l; return f ? (-d + this.sqrt(d * d - 2 * f * (c * c / (-2 * l) - a + l / 2 + n - o / 2))) / f + i : (i + h) / 2 }, i.prototype.rightBreakPoint = function(e, t) { var r = e.rbNext; if (r) return this.leftBreakPoint(r, t); var i = e.site; return i.y === t ? i.x : 1 / 0 }, i.prototype.detachBeachsection = function(e) { this.detachCircleEvent(e), this.beachline.rbRemoveNode(e), this.beachsectionJunkyard.push(e) }, i.prototype.removeBeachsection = function(e) { var t = e.circleEvent, r = t.x, i = t.ycenter, n = this.createVertex(r, i), o = e.rbPrevious, s = e.rbNext, h = [e], a = Math.abs; this.detachBeachsection(e); for (var l = o; l.circleEvent && a(r - l.circleEvent.x) < 1e-9 && a(i - l.circleEvent.ycenter) < 1e-9;) o = l.rbPrevious, h.unshift(l), this.detachBeachsection(l), l = o; h.unshift(l), this.detachCircleEvent(l); for (var c = s; c.circleEvent && a(r - c.circleEvent.x) < 1e-9 && a(i - c.circleEvent.ycenter) < 1e-9;) s = c.rbNext, h.push(c), this.detachBeachsection(c), c = s; h.push(c), this.detachCircleEvent(c); var f, d = h.length; for (f = 1; f < d; f++) c = h[f], l = h[f - 1], this.setEdgeStartpoint(c.edge, l.site, c.site, n); l = h[0], c = h[d - 1], c.edge = this.createEdge(l.site, c.site, void 0, n), this.attachCircleEvent(l), this.attachCircleEvent(c) }, i.prototype.addBeachsection = function(e) { for (var t, r, i, n, o = e.x, s = e.y, h = this.beachline.root; h;) if (i = this.leftBreakPoint(h, s) - o, i > 1e-9) h = h.rbLeft; else { if (n = o - this.rightBreakPoint(h, s), !(n > 1e-9)) { i > -1e-9 ? (t = h.rbPrevious, r = h) : n > -1e-9 ? (t = h, r = h.rbNext) : t = r = h; break } if (!h.rbRight) { t = h; break } h = h.rbRight } var a = this.createBeachsection(e); if (this.beachline.rbInsertSuccessor(t, a), t || r) { if (t === r) return this.detachCircleEvent(t), r = this.createBeachsection(t.site), this.beachline.rbInsertSuccessor(a, r), a.edge = r.edge = this.createEdge(t.site, a.site), this.attachCircleEvent(t), void this.attachCircleEvent(r); if (t && !r) return void(a.edge = this.createEdge(t.site, a.site)); if (t !== r) { this.detachCircleEvent(t), this.detachCircleEvent(r); var l = t.site, c = l.x, f = l.y, d = e.x - c, u = e.y - f, b = r.site, p = b.x - c, v = b.y - f, g = 2 * (d * v - u * p), y = d * d + u * u, x = p * p + v * v, R = this.createVertex((v * y - u * x) / g + c, (d * x - p * y) / g + f); return this.setEdgeStartpoint(r.edge, l, b, R), a.edge = this.createEdge(l, e, void 0, R), r.edge = this.createEdge(e, b, void 0, R), this.attachCircleEvent(t), void this.attachCircleEvent(r) } } }, i.prototype.CircleEvent = function() { this.arc = null, this.rbLeft = null, this.rbNext = null, this.rbParent = null, this.rbPrevious = null, this.rbRed = !1, this.rbRight = null, this.site = null, this.x = this.y = this.ycenter = 0 }, i.prototype.attachCircleEvent = function(e) { var t = e.rbPrevious, r = e.rbNext; if (t && r) { var i = t.site, n = e.site, o = r.site; if (i !== o) { var s = n.x, h = n.y, a = i.x - s, l = i.y - h, c = o.x - s, f = o.y - h, d = 2 * (a * f - l * c); if (!(d >= -2e-12)) { var u = a * a + l * l, b = c * c + f * f, p = (f * u - l * b) / d, v = (a * b - c * u) / d, g = v + h, y = this.circleEventJunkyard.pop(); y || (y = new this.CircleEvent), y.arc = e, y.site = n, y.x = p + s, y.y = g + this.sqrt(p * p + v * v), y.ycenter = g, e.circleEvent = y; for (var x = null, R = this.circleEvents.root; R;) if (y.y < R.y || y.y === R.y && y.x <= R.x) { if (!R.rbLeft) { x = R.rbPrevious; break } R = R.rbLeft } else { if (!R.rbRight) { x = R; break } R = R.rbRight } this.circleEvents.rbInsertSuccessor(x, y), x || (this.firstCircleEvent = y) } } } }, i.prototype.detachCircleEvent = function(e) { var t = e.circleEvent; t && (t.rbPrevious || (this.firstCircleEvent = t.rbNext), this.circleEvents.rbRemoveNode(t), this.circleEventJunkyard.push(t), e.circleEvent = null) }, i.prototype.connectEdge = function(e, t) { var r = e.vb; if (r) return !0; var i, n, o = e.va, s = t.xl, h = t.xr, a = t.yt, l = t.yb, c = e.lSite, f = e.rSite, d = c.x, u = c.y, b = f.x, p = f.y, v = (d + b) / 2, g = (u + p) / 2; if (this.cells[c.voronoiId].closeMe = !0, this.cells[f.voronoiId].closeMe = !0, p !== u && (i = (d - b) / (p - u), n = g - i * v), void 0 === i) { if (v < s || v >= h) return !1; if (d > b) { if (!o || o.y < a) o = this.createVertex(v, a); else if (o.y >= l) return !1; r = this.createVertex(v, l) } else { if (!o || o.y > l) o = this.createVertex(v, l); else if (o.y < a) return !1; r = this.createVertex(v, a) } } else if (i < -1 || i > 1) if (d > b) { if (!o || o.y < a) o = this.createVertex((a - n) / i, a); else if (o.y >= l) return !1; r = this.createVertex((l - n) / i, l) } else { if (!o || o.y > l) o = this.createVertex((l - n) / i, l); else if (o.y < a) return !1; r = this.createVertex((a - n) / i, a) } else if (u < p) { if (!o || o.x < s) o = this.createVertex(s, i * s + n); else if (o.x >= h) return !1; r = this.createVertex(h, i * h + n) } else { if (!o || o.x > h) o = this.createVertex(h, i * h + n); else if (o.x < s) return !1; r = this.createVertex(s, i * s + n) } return e.va = o, e.vb = r, !0 }, i.prototype.clipEdge = function(e, t) { var r = e.va.x, i = e.va.y, n = e.vb.x, o = e.vb.y, s = 0, h = 1, a = n - r, l = o - i, c = r - t.xl; if (0 === a && c < 0) return !1; var f = -c / a; if (a < 0) { if (f < s) return !1; f < h && (h = f) } else if (a > 0) { if (f > h) return !1; f > s && (s = f) } if (c = t.xr - r, 0 === a && c < 0) return !1; if (f = c / a, a < 0) { if (f > h) return !1; f > s && (s = f) } else if (a > 0) { if (f < s) return !1; f < h && (h = f) } if (c = i - t.yt, 0 === l && c < 0) return !1; if (f = -c / l, l < 0) { if (f < s) return !1; f < h && (h = f) } else if (l > 0) { if (f > h) return !1; f > s && (s = f) } if (c = t.yb - i, 0 === l && c < 0) return !1; if (f = c / l, l < 0) { if (f > h) return !1; f > s && (s = f) } else if (l > 0) { if (f < s) return !1; f < h && (h = f) } return s > 0 && (e.va = this.createVertex(r + s * a, i + s * l)), h < 1 && (e.vb = this.createVertex(r + h * a, i + h * l)), (s > 0 || h < 1) && (this.cells[e.lSite.voronoiId].closeMe = !0, this.cells[e.rSite.voronoiId].closeMe = !0), !0 }, i.prototype.clipEdges = function(e) { for (var t, r = this.edges, i = r.length, n = Math.abs; i--;) t = r[i], (!this.connectEdge(t, e) || !this.clipEdge(t, e) || n(t.va.x - t.vb.x) < 1e-9 && n(t.va.y - t.vb.y) < 1e-9) && (t.va = t.vb = null, r.splice(i, 1)) }, i.prototype.closeCells = function(e) { for (var t, r, i, n, o, s, h, a, l, c = e.xl, f = e.xr, d = e.yt, u = e.yb, b = this.cells, p = b.length, v = Math.abs; p--;) if (t = b[p], t.prepareHalfedges() && t.closeMe) { for (i = t.halfedges, n = i.length, r = 0; r < n;) { if (s = i[r].getEndpoint(), a = i[(r + 1) % n].getStartpoint(), v(s.x - a.x) >= 1e-9 || v(s.y - a.y) >= 1e-9) switch (!0) { case this.equalWithEpsilon(s.x, c) && this.lessThanWithEpsilon(s.y, u): if (l = this.equalWithEpsilon(a.x, c), h = this.createVertex(c, l ? a.y : u), o = this.createBorderEdge(t.site, s, h), r++, i.splice(r, 0, this.createHalfedge(o, t.site, null)), n++, l) break; s = h; case this.equalWithEpsilon(s.y, u) && this.lessThanWithEpsilon(s.x, f): if (l = this.equalWithEpsilon(a.y, u), h = this.createVertex(l ? a.x : f, u), o = this.createBorderEdge(t.site, s, h), r++, i.splice(r, 0, this.createHalfedge(o, t.site, null)), n++, l) break; s = h; case this.equalWithEpsilon(s.x, f) && this.greaterThanWithEpsilon(s.y, d): if (l = this.equalWithEpsilon(a.x, f), h = this.createVertex(f, l ? a.y : d), o = this.createBorderEdge(t.site, s, h), r++, i.splice(r, 0, this.createHalfedge(o, t.site, null)), n++, l) break; s = h; case this.equalWithEpsilon(s.y, d) && this.greaterThanWithEpsilon(s.x, c): if (l = this.equalWithEpsilon(a.y, d), h = this.createVertex(l ? a.x : c, d), o = this.createBorderEdge(t.site, s, h), r++, i.splice(r, 0, this.createHalfedge(o, t.site, null)), n++, l) break; if (s = h, l = this.equalWithEpsilon(a.x, c), h = this.createVertex(c, l ? a.y : u), o = this.createBorderEdge(t.site, s, h), r++, i.splice(r, 0, this.createHalfedge(o, t.site, null)), n++, l) break; if (s = h, l = this.equalWithEpsilon(a.y, u), h = this.createVertex(l ? a.x : f, u), o = this.createBorderEdge(t.site, s, h), r++, i.splice(r, 0, this.createHalfedge(o, t.site, null)), n++, l) break; if (s = h, l = this.equalWithEpsilon(a.x, f), h = this.createVertex(f, l ? a.y : d), o = this.createBorderEdge(t.site, s, h), r++, i.splice(r, 0, this.createHalfedge(o, t.site, null)), n++, l) break; default: throw "Voronoi.closeCells() > this makes no sense!" } r++ } t.closeMe = !1 } }, i.prototype.quantizeSites = function(e) { for (var t, r = this.ε, i = e.length; i--;) t = e[i], t.x = Math.floor(t.x / r) * r, t.y = Math.floor(t.y / r) * r }, i.prototype.recycle = function(e) { if (e) { if (!(e instanceof this.Diagram)) throw "Voronoi.recycleDiagram() > Need a Diagram object."; this.toRecycle = e } }, i.prototype.compute = function(e, t) { var r = new Date; this.reset(), this.toRecycle && (this.vertexJunkyard = this.vertexJunkyard.concat(this.toRecycle.vertices), this.edgeJunkyard = this.edgeJunkyard.concat(this.toRecycle.edges), this.cellJunkyard = this.cellJunkyard.concat(this.toRecycle.cells), this.toRecycle = null); var i = e.slice(0); i.sort(function(e, t) { var r = t.y - e.y; return r ? r : t.x - e.x }); for (var n, o, s, h = i.pop(), a = 0, l = this.cells;;) if (s = this.firstCircleEvent, h && (!s || h.y < s.y || h.y === s.y && h.x < s.x)) h.x === n && h.y === o || (l[a] = this.createCell(h), h.voronoiId = a++, this.addBeachsection(h), o = h.y, n = h.x), h = i.pop(); else { if (!s) break; this.removeBeachsection(s.arc) } this.clipEdges(t), this.closeCells(t); var c = new Date, f = new this.Diagram; return f.cells = this.cells, f.edges = this.edges, f.vertices = this.vertices, f.execTime = c.getTime() - r.getTime(), this.reset(), f }, "undefined" != typeof t && (t.exports = i) }, {}] }, {}, [1]);
CSS
body { background: linear-gradient(black, #3a3a3a); } h1 { position: absolute; bottom: 1vw; left: 1vw; font-size: 18px; font-family: monaco, consolas, monospace; color: rgba(255,255,255,0.5); }
HTML
Click to restart
Join Effecthub.com
Working with Global Gaming Artists and Developers!
Login
Sign Up
Or Login with Your Email Address:
Email
Password
Remember
Or Sign Up with Your Email Address:
Your Email
This field must contain a valid email
Set Password
Password should be at least 1 character
Stay informed via email