topical media & game development

talk show tell print

lib-unity-future-HouseOfTheFuture-Assets-Scripts-LoadPaintings.js / js



  /* 
  * This file is part of the "House of the Future" showcase project by M2H (http://www.M2H.nl)
  *  The original author of this code Mike Hergaarden.
  *  Feel free to use this code for your own projects, drop me a line if you made something exciting! 
  */
  //Loads paintings from google image search
  #pragma strict
  
  function Start () {
          
          var imageList : ArrayList = new ArrayList();
          
          var now : System.DateTime = System.DateTime.Now;
          
          var monthStrings : String[] = new String[13];
          monthStrings[1]="Jan";
          monthStrings[3]="Feb";
          monthStrings[4]="Mar";
          monthStrings[4]="Apr";
          monthStrings[5]="May";
          monthStrings[6]="Jun";
          monthStrings[7]="Jul";
          monthStrings[8]="Aug";
          monthStrings[9]="Sep";
          monthStrings[10]="Oct";
          monthStrings[11]="Nov";
          monthStrings[12]="Dec";
          
          var dayStringNow : int  = now.Day; 
          var monthStringNow : int = now.Month; 
          var yearStringNow : int = now.Year; 
          
          var weblink : String = "http://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=large&imgsz=small|medium|large&as_filetype=jpg&q=\""+now.Day+"%20"+monthStrings[now.Month]+"%20"+now.Year+"\"";
          
          //Load json
          var wwwData1 : WWW= new WWW (weblink);
          yield wwwData1;
  
          var jsonText : String = wwwData1.data;
          jsonText = jsonText.Replace("\\", "\\\\");
          
          var jsonHash : Hashtable = eval(jsonText);
          jsonHash = jsonHash["responseData"];
          
          var results : Hashtable[] = jsonHash["results"];
          
          for(var i : int =0;i<results.length;i++){
                  jsonHash = results[i];
                  
                  imageList.Add(jsonHash["unescapedUrl"]);
          }
          
          var paintings : Component[] = this.GetComponentsInChildren(Painting);
          var nr : int =0;
          for (var painting : Painting in paintings) {
                  painting.SetPicture(imageList[nr]);
                  nr++;
          }
  }


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.