Last active
August 26, 2024 19:22
-
-
Save Potherca/aaebb5d638fdb7bd7d2763238e4414b0 to your computer and use it in GitHub Desktop.
Run the Jewels cover randomizer - RTJ(rand)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<style> | |
html, body { | |
background-color: #333; | |
overflow: hidden; | |
margin: 0; | |
padding: 0; | |
} | |
canvas { | |
bottom: 0; | |
left: 0; | |
margin: auto; | |
position: fixed; | |
right: 0; | |
top: 0; | |
width: calc(min(100vw, 100vh) - 2rem); | |
} | |
h1 { | |
align-items: center; | |
display: flex; | |
height: 100vh; | |
justify-content: center; | |
margin: 0; | |
padding: 0; | |
} | |
title { | |
display: inline; | |
} | |
</style> | |
<h1><title>Run The Jewels</title></h1> | |
<script type="module"> | |
let images = [ | |
// "dibbs.jpg", | |
'RTJ4-deluxe.jpg', | |
'run-the-jewels-deluxe-european-edition-main.jpg', | |
// "Run-the-Jewels-RTJ-Cu4tro.webp", | |
'RTJ1_cover.webp', | |
'runTheJewels_2_cover.webp', | |
'runTheJewels_3_cover.webp', | |
'rtj4_cover.webp', | |
] | |
images = images.map((image) => { | |
const img = new Image() | |
img.src = image | |
return img | |
}) | |
await Promise.all(images.map((image) => { | |
return new Promise((resolve) => { | |
image.onload = resolve | |
}) | |
})) | |
let smallestImage = images[0] | |
images.forEach(image => { | |
if (image.width * image.height < smallestImage.width * smallestImage.height) { | |
smallestImage = image | |
} | |
}) | |
// Create a canvas for each image and resize it to the smallest image's dimensions | |
const canvasses = images.map((image) => { | |
const canvas = document.createElement('canvas') | |
canvas.width = smallestImage.width | |
canvas.height = smallestImage.height | |
const ctx = canvas.getContext('2d') | |
ctx.drawImage(image, 0, 0, smallestImage.width, smallestImage.height) | |
return canvas | |
}) | |
const canvas = document.createElement('canvas') | |
canvas.width = smallestImage.width | |
canvas.height = smallestImage.height | |
const ctx = canvas.getContext('2d') | |
let blockSize = smallestImage.width / 8 | |
for (let x = 0; x < smallestImage.width; x += blockSize) { | |
for (let y = 0; y < smallestImage.height; y += blockSize) { | |
const randomCanvas = canvasses[Math.floor(Math.random() * canvasses.length)] | |
ctx.drawImage(randomCanvas, x, y, blockSize, blockSize, x, y, blockSize, blockSize) | |
} | |
} | |
document.body.appendChild(canvas) | |
</script> | |
</html> |
This file has been truncated, but you can view the full file.
View raw
(Sorry about that, but we can’t show files that are this big right now.)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment