0x18b75119…b783sent to0x7c3ea2b7…0b18·#20,678,617·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;
let loadingSVG = createLoadingSVG();
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) {
removeLoadingSVG(loadingSVG);
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 createLoadingSVG() {
const svgNS = "http://www.w3.org/2000/svg";
const svg = document.createElementNS(svgNS, "svg");
svg.setAttributeNS(null, "viewBox", "0 0 122.14 122.14");
svg.setAttributeNS(null, "id", "Layer_1");
svg.setAttributeNS(null, "data-name", "Layer 1");
const path = document.createElementNS(svgNS, "path");
path.setAttributeNS(null, "d", "m0,122.14c67.46,0,122.14-54.69,122.14-122.14C54.69,0,0,54.69,0,122.14Zm86.37-35.78h-50.59v-50.59s50.59,0,50.59,0v50.59Z");
path.setAttributeNS(null, "style", "fill: #231f20; stroke-width: 0px;");
svg.appendChild(path);
svg.style.position = "absolute";
svg.style.top = "50%";
svg.style.left = "50%";
svg.style.transform = "translate(-50%, -50%)";
document.body.appendChild(svg);
return svg;
}
function removeLoadingSVG(svg) {
if (svg && svg.parentNode) {
svg.parentNode.removeChild(svg);
}
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
if (imgLoaded) {
// Redraw the image when the window is resized
loop();
}
}