-
-
Save Spongenuity/7e24e5ec994c3fadfff68f484274ab4e to your computer and use it in GitHub Desktop.
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
function fisherYatesShuffle(seed, array) { | |
let currentIndex = array.length; | |
let temporaryValue, randomIndex; | |
while (currentIndex !== 0) { | |
randomIndex = (seed + currentIndex) % currentIndex; | |
currentIndex -= 1; | |
temporaryValue = array[currentIndex]; | |
array[currentIndex] = array[randomIndex]; | |
array[randomIndex] = temporaryValue; | |
} | |
return array; | |
} | |
function generateIndices(seed, totalImages) { | |
const array = Array.from({ length: totalImages }, (_, i) => i + 1); | |
return fisherYatesShuffle(seed, array); | |
} | |
function selectImage(tokenId, totalImages = 10) { | |
const seed = 123456; | |
const indices = generateIndices(seed, totalImages); | |
console.log(`tokenId: ${tokenId}`) | |
console.log(`Selection: ${indices[tokenId % totalImages]}`) | |
return indices[tokenId % totalImages]; | |
} | |
const selectedImage = selectImage(tokenData.tokenId); // Must be changed to const "selectedImage = selectImage(tokenData.tokenId)" on AB | |
let img; | |
let CID = "QmQFCyck2pKvgMzn5KHHU32jAaDyDbjSBmD7YqnCpGwc8f"; | |
function preload() { | |
img = loadImage(`https://pinata.brightmoments.io/ipfs/${CID}/${selectedImage}.png`); | |
} | |
function setup() { | |
createCanvas(windowWidth, windowHeight); | |
} | |
function draw() { | |
background(255); | |
let imgAspectRatio = img.width / img.height; | |
let newWidth = width; | |
let newHeight = newWidth / imgAspectRatio; | |
if (newHeight > height) { | |
newHeight = height; | |
newWidth = newHeight * imgAspectRatio; | |
} | |
let x = (width - newWidth) / 2; | |
let y = (height - newHeight) / 2; | |
image(img, x, y, newWidth, newHeight); | |
} | |
function windowResized() { | |
resizeCanvas(windowWidth, windowHeight); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment