Le programme qui suit sert à diffuser au hasard les images contenues dans le dossier « data ». Les images affichées voient leur format s’adapter à l’écran lorsqu’elles excèdent ses dimensions.
String[] images;
IntList ordre;
int vitesse=1500; // une nouvelle image s'affiche toutes les 1,5 secondes (1500 millisecondes)
int next=0;
color fond=#000000;
void setup(){
fullScreen();
imageMode(CENTER);
ordre=new IntList();
images = listFileNames(dataPath(""));
background(fond);
}
void draw(){
if(ordre.size()==0){
for(int a=0;anext){
affiche(images[ordre.get(0)]);
ordre.remove(0);
next=millis()+vitesse;
}
}
String[] listFileNames(String dir) {
File file = new File(dir);
if (file.isDirectory()) {
String names[] = file.list();
String newNames[] = new String[0];
for(String n:names){
if(match(n, ".*\\.|jpg|jpeg|png|bmp|gif|JPG|JPEG|PNG|BMP|GIF")!=null){
newNames = (String[]) append(newNames, n);
}
}
return newNames ;
} else {
return null;
}
}
void affiche(String im){
background(fond);
PImage fichier = loadImage(im);
int largeur=fichier.width;
int hauteur=fichier.height;
if(largeur>width){
float pc = float(width)/largeur;
hauteur = round(pc*hauteur);
largeur=width;
}
if(hauteur>height){
float pc = float(height)/hauteur;
largeur = round(pc*largeur);
hauteur=height;
}
if(largeur>width||hauteur>height){
largeur=width;hauteur=height;
}
image(fichier, width/2, height/2, largeur, hauteur);
}









