Hello,
So i'm making a program that each time it runs it draws out a new 'collage.' I've loaded some images and each time it's run it's supposed to make the collage different (i.e. different locations for the items that are my images). I've got it working so the different types of items don't overlap whenever the program is run, but is there a way I can make it so that the images aren't drawn on top of each other? I'm drawing all the images through and array also. I tried using collision detection for the images, but since it's supposed to be 'random' i didn't know how to apply collisions to images from the array. Here is my code so far:
Code:
PImage [] items = new PImage[12];
PImage background1;
PImage background2;
float rx, ry, tn;
void setup(){
size(640, 480);
background1 = loadImage("background1.png");
background2 = loadImage("background2.png");
for (int i = 0; i < items.length; i++){
String imageName = "item-" + nf(i+1, 3) + ".png";
items[i] = loadImage(imageName);
}
if(random(0, 1) < 0.5){
background(background1);
}else{
background(background2);
}
noLoop();
}
void draw(){
tn = random(230, 255);
//onigri
for (int i = 0; i < 3; i++){
if(random(0, 1) < 0.5){
rx = random(530, 585);
ry = random(120, 320);
//tint(255, tn);
image(items[i], rx, ry);
if(random(0, 1) > 0.5){
rx = random(15, 75);
ry = random(255, 320);
image(items[i], rx, ry);
}
}
}
//ice cream
for (int j = 3; (j < 5)&&(j > 2); j++){
if(random(0, 1) < 0.5){
rx = random(300, 440);
ry = random(235, 360);
image(items[j], rx, ry);
/*if(random(0, 1) > 0.5){
image(items[j], rx + 30, ry + 70);
}*/
}
}
//batteries
for (int k = 6; (k < 8)&&(k > 5); k++){
if(random(0, 1) < 0.5){
rx = random(160, 210);
ry = random(240, 360);
image(items[k], rx, ry);
/*if(random(0, 1) > 0.5){
image(items[k], rx+20, ry+70);
}*/
}
}
//sushi
for (int l = 9; (l < 11)&&(l > 8); l++){
if(random(0, 1) < 0.5){
rx = random(25, 370);
ry = random(125, 170);
image(items[l], rx, ry);
}
}
Thanks for any help!