0xab368307…603fsent to0x7c3ea2b7…0b18·#18,356,363·view on Etherscan
function mulberry32(seed) {
let state = seed;
return function() {
state |= 0;
state = (state + 0x6D2B79F5) | 0;
let t = Math.imul(state ^ (state >>> 15), 1 | state);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296; // Normalize to [0, 1)
};
}
function fisherYatesShuffle(seed, array) {
let currentIndex = array.length;
let temporaryValue, randomIndex;
const rng = mulberry32(seed);
while (currentIndex !== 0) {
randomIndex = Math.floor(rng() * 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 = 539) {
const seed = 29614569;
const indices = generateIndices(seed, totalImages);
const selection = indices[tokenId % totalImages].toString().padStart(3, '0');
console.log(`tokenId: ${tokenId}`);
console.log(`Selection: ${selection}`);
return selection;
}
const selectedImage = selectImage(tokenData.tokenId);
let img;
let CID = "QmShbQd2SXzdSCjVmDu5RpLrSJ6tJy3toqP3EzQyNeKoE7";
function preload() {
img = loadImage(`https://ipfs.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);
}