Last active
August 16, 2022 13:50
-
-
Save ippsketch/c2822775f1fb9ecd550c65a2ca288aec to your computer and use it in GitHub Desktop.
p5.js script to generate collage of a fxhash project (using pre-downloaded images)
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
// use this to get download the images https://github.com/cables-and-pixels/pyfxhash | |
projectNumber = 17759; //fxhash project number | |
numberOfMints = 97; // number of mints for this project | |
gridSizeX = 10; // x-dimension grid size for the output collage | |
gridSizeY = Math.ceil(numberOfMints/gridSizeX); | |
aspectRatio = 3/4; //of the individual images (width/height) | |
let w = 2048*2; // width of output image | |
let h = w*gridSizeY/(gridSizeX*aspectRatio); | |
let dx = w/gridSizeX; | |
let dy = h/gridSizeY; | |
let fileName=[],img=[]; | |
function preload(){ | |
//preload the images (images in a folder that has the title of the projectNumber) | |
for (let i=0;i<numberOfMints;i++) { | |
fileName[i] = projectNumber+'/'+projectNumber+'-'+addLeadingZeros(i+1,4)+'.png'; | |
img[i] = loadImage(fileName[i]); | |
} | |
} | |
function setup(){ | |
createCanvas(w,h); | |
pixelDensity(1); | |
noLoop(); | |
imageMode(CENTER); | |
} | |
function draw(){ | |
for (let j=0;j<gridSizeY;j++){ | |
for (let i=0;i<gridSizeX;i++){ | |
let index = j*gridSizeX+i; | |
if (index>=numberOfMints) continue; | |
image(img[j*gridSizeX+i],i*dx+dx/2,j*dy+dy/2,dx+1,dy+1); | |
} | |
} | |
} | |
addLeadingZeros=(num, totalLength)=> {return String(num).padStart(totalLength, '0');} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment