I’m really new to Processing 3 and I’m really enjoying it but also about to rip my hair out! I am wanting to to create random collages that are built from .png assets. The code works fine at the moment and does (half) of what I want it to do.
I was wondering if anyone could help me with the following please?
- Applying a random positioning property to the images so they appear randomly across the canvas so they are not just in a line
- The same as above but a variable size
- Adding a code that stops the same image from duplicating in one collage
Thanks so much in advance, here is my code so far:
PImage[] images = new PImage[67];
int[] counters = new int[5];
int DISPLAY_TIME = 4000;
int lastTime;
int number = 0;
void setup()
{
size(600, 600);
for (int i = 0; i < images.length; i++)
{
images[i] = loadImage("Collage_" + nf(i+1, 2) + ".png");
images[i].resize(100,100);
}
lastTime = millis();
}
void draw()
{
background(250);
fill(250);
if (millis() - lastTime >= DISPLAY_TIME)
{
for( int i = 0; i < counters.length; i++){
counters[i] = int(random(0,images.length));
}
lastTime = millis();
}
for( int i = 0; i < counters.length; i++){
image (images[counters[i]], 40 + 30 * i, 50);}
}
void keyPressed(){
if(key == 's'){
println("Saving...");
String s = "screen" + nf(number,4) +".jpg";
save(s);
number++;
println("Done saving.");
}
}
Aucun commentaire:
Enregistrer un commentaire