Random Collage Generator • tim rodenbröker creative coding

Random Collage Generator

Published by Tim on Tuesday September 28, 2021

Last modified on January 25th, 2024 at 14:07

Vimeo

By loading the video, you agree to Vimeos’s privacy policy.
Learn more

Load video

// 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();
    }
  }
}

Bi-Weekly Updates

Active patrons in a paid tier get regular updates on new content, lessons and courses. For learners. On Fridays, 4pm CET.

Quarterly Newsletter

I share four e-mail newsletters per year: personal reflections on Creative Coding, Design and life with Technology, directly to your inbox.