int MAX_IN_ARRAY = 1000; PImage[] images = new PImage[MAX_IN_ARRAY]; picture myPicture; int numberFound = 0; int z = 0; PFont f; boolean bimage = false; String typing = ""; // Var to store text currently being typed String saved = ""; // Var to store saved text when return is hit String proxyURL = "http://itp.nyu.edu/icm/proxy/proxy.php?url="; //this is a relay station on itp that passes your request on, this allows your applet to work in a browser //I told you not to worry about this and just work in proccessing String myURL = ""; //String[] arrayOfLines = loadStrings(myURL); void setup(){ size(600,450,P3D); myPicture = new picture(); f = loadFont("1942report-20.vlw"); //background(0); } void draw(){ int indent = 25; background(0); //Set the font and fill for text fill(255); textFont(f); textMode(SCREEN); //Display Everything text("Click in this applet and type one word. \nHit return to find the related images.",indent,40); text(typing,indent,100); fill(200,200,255); text(saved,indent,130); if (bimage == true) { myPicture.getPicture(); } } void keyPressed() { if (key == '\n') { saved = typing; typing = ""; myURL = "http://images.google.com/images?hl=en&q=" + saved; String[] arrayOfLines = loadStrings(proxyURL + myURL); String oneLongString = join(arrayOfLines, ""); //the html coming back gets broken up in to lines but we want it in one long string, the join command does this String startingLandMark = "images?q=tbn:"; int startLookingAt = 0; //this is like our cursor to start looking after the last place we found somthing while(true){ //different kind of repeat loop that goes for an undetermined number of interations //this always comes before the thing I want, notice I used the escape quote \" to include a quote in the quoted int start = oneLongString.indexOf(startingLandMark,startLookingAt); //you want to include the landmark so don't do this + startingLandMark.length(); //find the first occurance of this landmark and then march forward past the end of the landmark //also notice that I used a variation of indexOf that starts looking not at the beginning of the string //instead at a point I specify, in this case after what I already found if (start == -1) { //this means it never found anything in which case we should give up the ghost break; //stops the repeat loop; } int end = oneLongString.indexOf(" ",start + startingLandMark.length() ); //look for the first end landmark, in this case a space, after the starting landmark String imageURL = "http://images.google.com/" + oneLongString.substring(start,end); //add google's default path println("image" + imageURL); images[numberFound] = loadImage(proxyURL + imageURL); numberFound++; startLookingAt = end + 1; if (numberFound >= MAX_IN_ARRAY ) { //don't overpack the array break; //stops the repeat loop; } } bimage = true; } else { typing = typing + key; myPicture.clearPicture(); numberFound = 0; } } class picture { void getPicture() { float angleIncrements = 2*PI/numberFound; //angle units between each picture, in radians 2*PI = 360 degrees int radius = 100; lights(); camera(width/2.0*mouseX/400, height/2.0, mouseY*-8, width/2.0, height/2.0, 0, 0, 1, 0); for(int i = 0; i < numberFound; i++){ noFill(); translate(0, 0, z-i*20); float thisAngle = i* angleIncrements; float x = radius*cos(thisAngle) + width/2-180; float y = radius*sin(thisAngle*.3) + height/2-110; image(images[i],x,y); } //background(0); } void clearPicture() { bimage = false; //saved = ""; myURL = ""; } }