let background = ["8490a049df88b531a025c7a2a7a615aa7169acc073bc1fd8a38fe10378339432i0", "fa12548bc92b6e7b0dd10f3a1cad90a2f880616f46156085b4fac5fb7933fe59i0"]; let body = ["285fdc79f2cf59f466d715eff4ff9487fed7664bd787916ee8c95dee46422c84i0"]; let clothes = ["686d1a50a3bf4e9aeda3d8add9c392cd04baf0d83fe50e81460330afb97d1ad1i0","c81d9f8b6226a41c319946d01ea6d3a8cda7f61dd2f3aaa083c5f33506860a8bi0"]; let eyes = ["3bca87436409168eb60ceb603e87ea64b7945c62b8ac3c7205b04aa21a638162i0","2f7b5f11e502b50dfc6eca45ea61d614c198eaf0ae614a32f2328d3eff73319di0"]; let mouth = ["fc053f1365a44d3e9f4b3515373db08d9763530ddb36d7a8c86cd620eae67303i0","5c5d42b7f10a3b5c26657996d4150c3167a0e215c98a5e6c19034d33822e09f7i0","fe142757d4f14be98dfb23cb97f25bf56491f363cd6ebc22462c2cfe126743f5i0"]; let head = ["720bf941be263dfa2de522a418c6fc4efeb004a141bef3bdab175cd770a61775i0","dea15f9b394c7eb4bbdbbe4f1cfb3f3fa76da4beeb60eddfe81f6b06d7bbe10fi0","fe142757d4f14be98dfb23cb97f25bf56491f363cd6ebc22462c2cfe126743f5i0"]; let blockHeight; const mod = 2 ** 31 - 1; const a = 1103515245; const c = 12345; let seed; async function getBlockHeight() { const response = await fetch('/blockheight'); blockHeight = await response.text() || 0; seed = hashCode(blockHeight); init(); } function random() { seed = (a * seed + c) % mod; return seed / mod; } function getRandomTrait(array) { return array[Math.floor(random() * array.length)]; } function hashCode(str) { let hash = 0; if (str.length === 0) { return hash; } for (let i = 0; i < str.length; i++) { const char = str.charCodeAt(i); hash = (hash << 5) - hash + char; hash = hash & hash; } return Math.abs(hash); } async function draw(canvas, images) { const ctx = canvas.getContext('2d'); for (let imgSrc of images) { const img = new Image(); img.src = await fetch(imgSrc).then(r => r.blob()).then(URL.createObjectURL); await new Promise(resolve => { img.onload = () => { ctx.drawImage(img, 0, 0, canvas.width, canvas.height); resolve(); }; }); } } function init() { // Initial Draw draw(document.getElementById('c'), [getRandomTrait(background), getRandomTrait(body), getRandomTrait(clothes), getRandomTrait(eyes), getRandomTrait(mouth), getRandomTrait(head)]); } getBlockHeight(); setInterval(getBlockHeight, 60000);