xxxxxxxxxx
// define an array variable with all of the files you want to load
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"
];
// Define an empty array to assign all of the loaded images
let imgs = [];
// Define an image id
let imgID = 0;
function preload() {
// load all images through loop into imgs array
for (let i = 0; i < sources.length; i++) {
imgs[i] = loadImage(sources[i]);
}
}
function setup() {
createCanvas(windowWidth, windowHeight);
background(100);
noLoop();
imageMode(CENTER);
angleMode(DEGREES);
}
function draw() {
background(255);
let x = width / 2;
let y = height / 2;
let rot = random(-50,50);
//different blending modes.
blendMode(MULTIPLY);
let itr = random(-50,100);
push();
translate(x, y);
scale(1,1); // NO mirror
rotate(rot);
image(imgs[imgID], itr, 0);
pop();
push();
translate(x, y);
scale(-1,1); // Mirror horizontal
rotate(rot);
image(imgs[imgID], itr, 0);
pop();
push();
translate(x, y);
scale(-1,-1); // Mirror horizontal, vertical
rotate(rot);
image(imgs[imgID], itr, 0);
pop();
push();
translate(x, y);
scale(1,-1); // Mirror vertical
rotate(rot);
image(imgs[imgID], itr, 0);
pop();
}
function keyPressed() {
if (key == 'e') {
clear();
draw();
imgID = round(random(0,sources.length -1));
}
if (key == 's') {
save("export.jpg");
}
}