xxxxxxxxxx
//Collage
//Images
let sources = [
"1.png",
"2.png",
"3.png",
"4.png",
"5.png",
"6.png",
"7.png",
"8.png",
"9.png",
"10.png",
"11.png",
"12.png",
"13.png",
"14.png",
"15.png",
"16.png",
"17.png",
"18.png",
"19.png",
"20.png",
];
//Assigning all of the images
let images = [];
//Image id
let imageID = 1;
function preload() {
// load all images through loop into imgs array
for (let j = 0; j < sources.length; j++) {
images[j] = loadImage(sources[j]);
}
}
function setup() {
//Creates the application window params: width=600, height=600
createCanvas(600, 600);
noLoop();
}
function draw() {
//Background color
background(255);
//Centers the image
imageMode(CENTER);
//Loops the images
for (let j = 0; j < sources.length; j++) {
let a = width / 2 + random(-200,200);
let b = height / 2 + random(-200,200);
image(images[j], a, b);
}
}
//When the "r" key is pressed the images get randomized
//When the "s" key is pressed the collage gets saved
function keyPressed() {
if (key == 'r') {
draw();
}
if (key == 's') {
save("export.jpg");
}
}