0x18b75119…b783sent to0x7c3ea2b7…0b18·#20,678,746·view on Etherscan
let BASE_URL = "https://pinata.brightmoments.io/ipfs";
let CID = "QmaHrqnoqGnkyHzkrku6mjS2gpGQorRfzP9HawHgwHtuE6";
let TOTAL_IMAGES = 100;
const SEED = 29614578;
const fileType=".png";
const pinataGatewayToken= "y2RzmHlL19ONzg0XSiSssf0oiTUA9LEeTyMuds3Jq8KH103TdGHPLW929XibZCrs";
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;
};
}
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);
return fisherYatesShuffle(SEED, array);
}
function selectImage(tokenId, totalImages) {
const indices = generateIndices(SEED, totalImages);
const selection = indices[tokenId % totalImages];
console.log(`tokenId: ${tokenId}`);
console.log(`Selection: ${selection}`);
return selection;
}
let tokenId = tokenData.tokenId;
const selectedImage = selectImage(tokenId, TOTAL_IMAGES);
let img;
let imgLoaded = false;
function preload() {
// Load image and set flag when done
let loadingDiv = select('#p5_loading');
if (loadingDiv) {
loadingDiv.hide();
}
const imageUrl = `${BASE_URL}/${CID}/${selectedImage}.png/?pinataGatewayToken=${pinataGatewayToken}`;
console.log(imageUrl);
img = loadImage(imageUrl, () => {
imgLoaded = true;
});
}
function setup() {
createCanvas(windowWidth, windowHeight);
}
function draw() {
background(255);
if (imgLoaded) {
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);
if (imgLoaded) {
// Redraw the image when the window is resized
loop();
}
}