/* OpenProcessing Tweak of *@*http://www.openprocessing.org/sketch/132752*@* */ /* !do not delete the line above, required for linking your tweak if you upload again */ // // GET GOOGLE IMAGES SEARCH RESULTS // // I use the ajax.googleapis.com json search results to fetch the image // urls into a string array and display them one at a time // // Youssef Faltas, Feb 2014 //import java.util.Calendar; String searchTerm = "landscape%20Loire"; int numofResults = 12; // choose a multiple of four String[] imgUrls = new String[0]; String[] links = new String[0]; JSONArray results; JSONObject response; PImage img2; int i =0; int t =0; int tileCountX = 12; int tileCountY = 9; float tileWidth, tileHeight; int imageCount = tileCountX*tileCountY; int currentImage = 0; int gridX = 0; int gridY = 0; void setup() { size(1024,768,P3D); links = img_urls(numofResults); // returns an array of image url strings int t = second(); tileWidth = width / (float)tileCountX; tileHeight = height / (float)tileCountY; // start a clock } void draw(){ float posX = tileWidth*gridX; float posY = tileHeight*gridY; if ( second() < t ) t = 0 ; // fixing the clock at the start of every minute if ( i == numofResults ) i = 0 ; // starting over when we reach the final result if (second() > t+1 ) // display a new image every two seconds { t = second(); i++; img2 = loadImage(links[i],"jpg"); googleImg(); if (img2 != null ) image(img2, posX, posY, tileWidth, tileHeight); // display and fit image to display window // new grid position // gridX++; // if (gridX >= tileCountX) { // gridX = 0; // gridY++; // } // println(i); // println(links[i]); // prints its link to console } } String[] img_urls(int fours) { String[] url = new String[fours]; String[] links = new String[4*fours]; for(int t=0; t