Random Collage Generator
// Declare and initialize and array of images
PImage[] images = new PImage[15];
void setup() {
size(900, 900);
// Slow down the whole thing
frameRate(1);
// Load images to the array
for (int i = 0; i < images.length; i++) {
// Load the specific image to the slot in the array
images[i] = loadImage(i + ".png");
// resize that image
images[i].resize(2000, 0);
// Apply a grayscale filter to the image
images[i].filter(GRAY);
}
// center images and rectangles
rectMode(CENTER);
imageMode(CENTER);
}
void draw() {
background(#f1f1f1);
// create a red ellipse at the center of the background
fill(#ff0000);
noStroke();
ellipse(width/2, height/2, 700, 700);
for (int i = 0; i < images.length; i++) {
// Get the specific image
PImage img = images[i];
// set random x and y positions
float x = random(width);
float y = random(height);
// decide how large the image shall be
float scalar = random(0.1, 0.5);
// place the image with a probability of 50%
if (random(1) < 0.5) {
// place the image
push();
translate(x, y);
scale(scalar);
image(img, 0, 0);
pop();
}
}
}








Enjoying the content?
Since 2018, I have published 236 interviews, case studies, and tutorials, along with over 329 lessons in 21 online courses – and there's more to come! If you want to get full access or simply support my work and help keep this platform thriving, please consider supporting me on Patreon. Thank you very much!
