!function(t, e) { "object" == typeof exports && "undefined" != typeof module ? module.exports = e() : "function" == typeof define && define.amd ? define(e) : (t || self).ColorThief = e() }(this, function() { if (!t) var t = { map: function(t, e) { var n = {}; return e ? t.map(function(t, r) { return n.index = r, e.call(n, t) }) : t.slice() }, naturalOrder: function(t, e) { return t < e ? -1 : t > e ? 1 : 0 }, sum: function(t, e) { var n = {}; return t.reduce(e ? function(t, r, o) { return n.index = o, t + e.call(n, r) } : function(t, e) { return t + e }, 0) }, max: function(e, n) { return Math.max.apply(null, n ? t.map(e, n) : e) } }; var e = function() { function e(t, e, n) { return (t << 10) + (e << 5) + n } function n(t) { var e = [], n = !1; function r() { e.sort(t), n = !0 } return { push: function(t) { e.push(t), n = !1 }, peek: function(t) { return n || r(), void 0 === t && (t = e.length - 1), e[t] }, pop: function() { return n || r(), e.pop() }, size: function() { return e.length }, map: function(t) { return e.map(t) }, debug: function() { return n || r(), e } } } function r(t, e, n, r, o, $, a) { var l = this; l.r1 = t, l.r2 = e, l.g1 = n, l.g2 = r, l.b1 = o, l.b2 = $, l.histo = a } function o() { this.vboxes = new n(function(e, n) { return t.naturalOrder(e.vbox.count() * e.vbox.volume(), n.vbox.count() * n.vbox.volume()) }) } function $(n, r) { if (r.count()) { var o = r.r2 - r.r1 + 1, $ = r.g2 - r.g1 + 1, a = t.max([o, $, r.b2 - r.b1 + 1]); if (1 == r.count()) return [r.copy()]; var l, h, u, c, s = 0, f = [], _ = []; if (a == o) for (l = r.r1; l <= r.r2; l++) { for (c = 0, h = r.g1; h <= r.g2; h++) for (u = r.b1; u <= r.b2; u++) c += n[e(l, h, u)] || 0; f[l] = s += c } else if (a == $) for (l = r.g1; l <= r.g2; l++) { for (c = 0, h = r.r1; h <= r.r2; h++) for (u = r.b1; u <= r.b2; u++) c += n[e(h, l, u)] || 0; f[l] = s += c } else for (l = r.b1; l <= r.b2; l++) { for (c = 0, h = r.r1; h <= r.r2; h++) for (u = r.g1; u <= r.g2; u++) c += n[e(h, u, l)] || 0; f[l] = s += c } return f.forEach(function(t, e) { _[e] = s - t }), function(t) { var e, n, o, $, a, h = t + "1", u = t + "2", c = 0; for (l = r[h]; l <= r[u]; l++) if (f[l] > s / 2) { for (o = r.copy(), $ = r.copy(), a = (e = l - r[h]) <= (n = r[u] - l) ? Math.min(r[u] - 1, ~~(l + n / 2)) : Math.max(r[h], ~~(l - 1 - e / 2)); !f[a];) a++; for (c = _[a]; !c && f[a - 1];) c = _[--a]; return o[u] = a, $[h] = o[u] + 1, [o, $] } }(a == o ? "r" : a == $ ? "g" : "b") } } return r.prototype = { volume: function(t) { var e = this; return e._volume && !t || (e._volume = (e.r2 - e.r1 + 1) * (e.g2 - e.g1 + 1) * (e.b2 - e.b1 + 1)), e._volume }, count: function(t) { var n = this, r = n.histo; if (!n._count_set || t) { var o, $, a, l = 0; for (o = n.r1; o <= n.r2; o++) for ($ = n.g1; $ <= n.g2; $++) for (a = n.b1; a <= n.b2; a++) l += r[e(o, $, a)] || 0; n._count = l, n._count_set = !0 } return n._count }, copy: function() { return new r(this.r1, this.r2, this.g1, this.g2, this.b1, this.b2, this.histo) }, avg: function(t) { var n = this, r = n.histo; if (!n._avg || t) { var o, $, a, l, h = 0, u = 0, c = 0, s = 0; for ($ = n.r1; $ <= n.r2; $++) for (a = n.g1; a <= n.g2; a++) for (l = n.b1; l <= n.b2; l++) h += o = r[e($, a, l)] || 0, u += o * ($ + .5) * 8, c += o * (a + .5) * 8, s += o * (l + .5) * 8; n._avg = h ? [~~(u / h), ~~(c / h), ~~(s / h)] : [~~(8 * (n.r1 + n.r2 + 1) / 2), ~~(8 * (n.g1 + n.g2 + 1) / 2), ~~(8 * (n.b1 + n.b2 + 1) / 2)] } return n._avg }, contains: function(t) { var e = t[0] >> 3; return gval = t[1] >> 3, bval = t[2] >> 3, e >= this.r1 && e <= this.r2 && gval >= this.g1 && gval <= this.g2 && bval >= this.b1 && bval <= this.b2 } }, o.prototype = { push: function(t) { this.vboxes.push({ vbox: t, color: t.avg() }) }, palette: function() { return this.vboxes.map(function(t) { return t.color }) }, size: function() { return this.vboxes.size() }, map: function(t) { for (var e = this.vboxes, n = 0; n < e.size(); n++) if (e.peek(n).vbox.contains(t)) return e.peek(n).color; return this.nearest(t) }, nearest: function(t) { for (var e, n, r, o = this.vboxes, $ = 0; $ < o.size(); $++)((n = Math.sqrt(Math.pow(t[0] - o.peek($).color[0], 2) + Math.pow(t[1] - o.peek($).color[1], 2) + Math.pow(t[2] - o.peek($).color[2], 2))) < e || void 0 === e) && (e = n, r = o.peek($).color); return r }, forcebw: function() { var e = this.vboxes; e.sort(function(e, n) { return t.naturalOrder(t.sum(e.color), t.sum(n.color)) }); var n = e[0].color; n[0] < 5 && n[1] < 5 && n[2] < 5 && (e[0].color = [0, 0, 0]); var r = e.length - 1, o = e[r].color; o[0] > 251 && o[1] > 251 && o[2] > 251 && (e[r].color = [255, 255, 255]) } }, { quantize: function(a, l) { if (!a.length || l < 2 || l > 256) return !1; var h, u, c, s, f, _, d, g, p, v, m, b, y, x, w = (h = a, c = Array(32768), h.forEach(function(t) { c[u = e(t[0] >> 3, t[1] >> 3, t[2] >> 3)] = (c[u] || 0) + 1 }), c); w.forEach(function() {}); var k = (s = a, f = w, p = 1e6, v = 0, m = 1e6, b = 0, y = 1e6, x = 0, s.forEach(function(t) { (_ = t[0] >> 3) < p ? p = _ : _ > v && (v = _), (d = t[1] >> 3) < m ? m = d : d > b && (b = d), (g = t[2] >> 3) < y ? y = g : g > x && (x = g) }), new r(p, v, m, b, y, x, f)), C = new n(function(e, n) { return t.naturalOrder(e.count(), n.count()) }); function E(t, e) { for (var n, r = t.size(), o = 0; o < 1e3;) { if (r >= e || o++ > 1e3) return; if ((n = t.pop()).count()) { var a = $(w, n), l = a[0], h = a[1]; if (!l) return; t.push(l), h && (t.push(h), r++) } else t.push(n), o++ } } C.push(k), E(C, .75 * l); for (var z = new n(function(e, n) { return t.naturalOrder(e.count() * e.volume(), n.count() * n.volume()) }); C.size();) z.push(C.pop()); E(z, l); for (var I = new o; z.size();) I.push(z.pop()); return I } } }().quantize, n = function(t) { this.canvas = document.createElement("canvas"), this.context = this.canvas.getContext("2d"), this.width = this.canvas.width = t.naturalWidth, this.height = this.canvas.height = t.naturalHeight, this.context.drawImage(t, 0, 0, this.width, this.height) }; n.prototype.getImageData = function() { return this.context.getImageData(0, 0, this.width, this.height) }; var r = function() {}; return r.prototype.getColor = function(t, e) { return void 0 === e && (e = 10), this.getPalette(t, 5, e)[0] }, r.prototype.getPalette = function(t, r, o) { var $ = function(t) { var e = t.colorCount, n = t.quality; if (void 0 !== e && Number.isInteger(e)) { if (1 === e) throw Error("colorCount should be between 2 and 20. To get one color, call getColor() instead of getPalette()"); e = Math.min(e = Math.max(e, 2), 20) } else e = 10; return (void 0 === n || !Number.isInteger(n) || n < 1) && (n = 10), { colorCount: e, quality: n } }({ colorCount: r, quality: o }), a = new n(t), l = e(function(t, e, n) { for (var r, o, $, a, l, h = t, u = [], c = 0; c < e; c += n) o = h[0 + (r = 4 * c)], $ = h[r + 1], a = h[r + 2], (void 0 === (l = h[r + 3]) || l >= 125) && (o > 250 && $ > 250 && a > 250 || u.push([o, $, a])); return u }(a.getImageData().data, a.width * a.height, $.quality), $.colorCount); return l ? l.palette() : null }, r.prototype.getColorFromUrl = function(t, e, n) { var r = this, o = document.createElement("img"); o.addEventListener("load", function() { e(r.getPalette(o, 5, n)[0], t) }), o.src = t }, r.prototype.getImageData = function(t, e) { var n = new XMLHttpRequest; n.open("GET", t, !0), n.responseType = "arraybuffer", n.onload = function() { if (200 == this.status) { var t = new Uint8Array(this.response); i = t.length; for (var n = Array(i), r = 0; r < t.length; r++) n[r] = String.fromCharCode(t[r]); var o = n.join(""); e("data:image/png;base64," + window.btoa(o)) } }, n.send() }, r.prototype.getColorAsync = function(t, e, n) { var r = this; this.getImageData(t, function(t) { var o = document.createElement("img"); o.addEventListener("load", function() { e(r.getPalette(o, 5, n)[0], this) }), o.src = t }) }, r }), window.onload = function() { let seed = document.getElementById("PepGen").getAttribute("data-s"), rngState, circles = []; function seedRandom() { let seedInt = 0; for (let i = 0; i < seed.length; i++) { seedInt = (seedInt << 5) - seedInt + seed.charCodeAt(i); seedInt |= 0; // Convert to 32bit integer } rngState = seedInt; } function seededRandom() { const x = Math.sin(rngState++) * 10000; return x - Math.floor(x); } function createCircles() { seedRandom(); for (let i = 0; i < 100; i++) { circles.push({ x: seededRandom() * canvas.width, y: seededRandom() * canvas.height, radius: seededRandom() * 20, dx: seededRandom() * 4 - 2, dy: seededRandom() * 4 - 2, color: `rgb(${seededRandom() * 255}, ${seededRandom() * 255}, ${seededRandom() * 255})` }); } } function animate() { context.clearRect(0, 0, canvas.width, canvas.height); circles.forEach(circle => { context.beginPath(); context.arc(circle.x, circle.y, circle.radius, 0, Math.PI * 2, false); context.fillStyle = circle.color; context.fill(); // Update circle position for animation circle.x += circle.dx; circle.y += circle.dy; // Boundary conditions if (circle.x < 0 || circle.x > canvas.width) circle.dx *= -1; if (circle.y < 0 || circle.y > canvas.height) circle.dy *= -1; }); requestAnimationFrame(animate); } let canvas = document.createElement("canvas"), context = canvas.getContext("2d"); canvas.width = window.innerWidth; canvas.height = window.innerHeight; document.body.appendChild(canvas); createCircles(); animate(); };