int s = 10; int blocksize = 255; int wwidth = 2 * blocksize; //set window width variable for size int wheight = 3 * blocksize; //set window height variable for size int f = 0; int i; float totalred,totalgreen,totalblue,r,g,b,ravg,gavg,bavg; int numberofsamples = s*s; //use this later instead of i to divide int totAverageStandard; int totAverageContestant; int deviance; //String contestant = ("/Users/browerpropulsionlaboratory/Documents/bpl business/BPL-003MMM/beautyContest/contestant.jpg"); String contestant = ("http://browerpropulsionlab.com/records/get/jpegbeauty.php"); //String contestant = ("http://127.0.0.1/~harvey/control/jpeg.php"); //this is the base filename for the saveFrame at the end String contestantfilename = "contestant"; PImage picture, picture2, picturesmall, picture2small; color coloravg , coloravg2; String newfilename,datastring; String extension = ".tif"; void setup() { size (wwidth,wheight); frameRate(.5); // this assingment calls the getnextfilename function // to find the next available filename //newfilename = getnextfilename(contestantfilename); newfilename = "contestant0002"; String contestantnumber = newfilename.substring(newfilename.length() - 4); datastring = "Contestant "+contestantnumber+"\n"; //println(newfilename); } void draw() { if (f == 0) { picture = loadImage("Moran.jpg"); image(picture, 0, 0); picture.resize(s,s); image(picture, 0, 0,s,s); loadPixels(); for ( i = 0; i < s*wwidth; i++) { color p = pixels[i]; r = red(p); g = green(p); b = blue(p); totalred += r; totalgreen += g; totalblue += b; //println(i+". r:"+r+" g:"+g+" b:"+b); /* since we're just getting the upper left corner of the size now we need to get the first row of s pixels, then, when we're ready for the next row, add the remaining window width (wwdidth - s, since s has already been done, then go for s more and again correc) % is modulo, ie, what is left over after division so if nothing is left over after i+1 is divided by s, it's time to jump to the next row down */ if ((i+1)%s == 0) { i += wwidth - s; } } ravg = round (totalred / numberofsamples); gavg = round (totalgreen / numberofsamples); bavg = round (totalblue / numberofsamples); totAverageStandard = round((ravg + gavg + bavg) / 3); println ("red Standard average: "+ravg); println ("green Standard average: "+gavg); println ("blue Standard average: "+bavg); println ("standard index: " + totAverageStandard); datastring += ("red Standard average: "+ravg+"\n"); datastring += ("green Standard average: "+gavg+"\n"); datastring += ("blue Standard average: "+bavg+"\n"); datastring += ("standard index: " + totAverageStandard+"\n"); coloravg = color(ravg, gavg, bavg); //end of standard image; new image to be loaded and pixels analyzed f++; } else if (f == 1) { picture2 = loadImage(contestant,"jpg"); image(picture2, 0, 0); picture2.resize(s, s); image(picture2, 0, 0, s, s); loadPixels(); totalred = 0; totalgreen = 0; totalblue = 0; for ( i = 0; i < s*wwidth; i++) { color p = pixels[i]; r = red(p); g = green(p); b = blue(p); totalred += r; totalgreen += g; totalblue += b; //println(i+". r:"+r+" g:"+g+" b:"+b); if ((i+1)%s == 0) { i += wwidth - s; } } ravg = round (totalred / numberofsamples); gavg = round (totalgreen / numberofsamples); bavg = round (totalblue / numberofsamples); totAverageContestant = round((ravg + gavg + bavg) / 3); println ("red Contestant average: "+ravg); println ("green Contestant average: "+gavg); println ("blue Contestant average: "+bavg); println ("Contestant index: " + totAverageContestant); deviance = (totAverageStandard - totAverageContestant); println ("Deviation from Standard " + deviance); datastring += ("red Contestant average: "+ravg+"\n"); datastring += ("green Contestant average: "+gavg+"\n"); datastring += ("blue Contestant average: "+bavg+"\n"); datastring += ("Contestant index: " + totAverageContestant+"\n"); datastring += ("Deviation from Standard " + deviance+"\n"); coloravg2 = color(ravg, gavg, bavg); f++; } else if (f == 2) { picturesmall = loadImage("Moran.jpg"); picture2small = loadImage(contestant,"jpg"); image(picturesmall, 0, 0, blocksize, blocksize); image(picture2small, blocksize, 0, blocksize,blocksize); f++; } else if (f == 3) { noSmooth(); image(picture, 0, blocksize,blocksize,blocksize); image(picture2, blocksize, blocksize,blocksize,blocksize); f++; } else if (f == 4) { println("color average " +coloravg); datastring += ("color average " +coloravg); fill(coloravg); noStroke(); rect(0,(2*blocksize),blocksize,blocksize); fill(coloravg2); rect(blocksize,(2*blocksize),blocksize,blocksize); f++; } else if (f == 5) { writestringtoimage (datastring); //this saveFrame saves to the newfilename variable // saveFrame(newfilename+extension); f=0; noLoop(); //contestant = selectFolder("select another contestant"); } } //this function checks each numbered filename until it finds a filename //which doesn't exist yet, then returns that filename String getnextfilename(String filename) { boolean gotfilename = false; int count = 0; String newfilename = filename+nf(count,4); File pathcheck = new File( sketchPath+"/"+newfilename+extension); while(!gotfilename) { if(pathcheck.exists()) { count++; newfilename = filename+nf(count,4); pathcheck = new File(sketchPath+"/"+newfilename+extension); } else { gotfilename = true; } } return newfilename; } Boolean writestringtoimage (String datastring) { PFont font; font = loadFont("Rockwell-12.vlw"); textFont(font); fill(coloravg2); text(datastring, (blocksize*0.15), (blocksize*2.2)); return true; }