• fullscreen
  • Circ.pde
  • DataStore.pde
  • NYT_nov21_f1circ.pde
  • class Circ { // give Classes names that begin with a capital letter to differentiate
      float x1;
      float y1;
      float diam;
      float Xspeed;
      float Yspeed;
      boolean mouse;
      float gravity;
      float fade;
      float spread;
    
      Circ(float tempX, float tempY, float diam_) { // "the constructor"
        x1 = tempX;
        y1 = tempY;
        diam = diam_;
        Xspeed = random(-1,1);
        Yspeed = random(-1,1);
        mouse = false;
        gravity = 0.5;
        fade = .01;
        spread = random(8,80);
      }
    
      void move() {
        if(go) {  //moves on click
    
          x1 = x1 + Xspeed/1.02;
          y1 = y1 + Yspeed/1.02;
    
          if (x1 >= width/2+spread || x1 <= width/2-spread) {
            Xspeed = Xspeed/1.02;
            //        Yspeed = Yspeed - .02;
          }
    
           if (y1 >= height/2+spread || y1 <= height/2-spread) {
            Yspeed = Yspeed/1.02;
          }
        }
      }
    
      void display() {
        if (mouse) { 
          fill(88,20,20);
    //      diam = 10;
        }  
        else {
          fill(230,20,20,200);
    //      diam = diam;
        }
        //    fill(250,250,255,150);
        if(go) {
          ellipse(x1,y1,diam, diam);
        }
        
      }
    
      void rollover(int mx, int my) { 
        // Left edge is x, Right edge is x + w
        if (mx > x1-diam/2 && mx < x1 + diam/2 && my > y1-diam/2 && my < y1 + diam/2) {
          mouse = true;
        } 
        else {
          mouse = false;
        }
      }
      
    }// end class
    
    
    public class DataStore {
      
      String cyear;
      String cmonth;
      
      String[] facetStrings;
      
      String word;
      String leadFacet;
      String secondFacet;
      
     /*FACETS: per_facet = person involved in article content
               classifiers_facet = setion/directory article is located in
               geo_facet = location article is about 
               org_facet = organization involved in article
               des_facet = gerneral subject of article (?)
               
     RESULTS:   "body": "Vivek Kundra is the chief information officer of the United States. His job is to help shape the use of technology in government and build tools to help the public navigate the incredible amount of data and information available. Mr. Kundra started his career in government in 2001 as the information technology director for Arlington County, Va.,",
                "byline": "By NICK BILTON",
                "date": "20101108",
                "title": "BITS; Online Security Guard for the U.S.",
                "url":"http:\/\/query.nytimes.com\/gst\/fullpage.html?res=9802EFDA1238F93BA35752C1A9669D8B63"
     */
     
      boolean isSpike;
      
      int total;
      JSONArray facets;
      JSONArray entries;
      
      DataStore() {};
      
    };
    
    import org.json.*;//import JSON library
    PFont f;
    
    String apiKey = "8258e5cc834626de062eafe00dd656c4:10:61866308"; //my NYT API key code
    String baseURL = "http://api.nytimes.com/svc/search/v1/article";
    String[] facetString = {
      "classifiers_facet","des_facet", "geo_facet","org_facet"
    };
    
    String typing = "";  // Variable to store text currently being typed
    String saved = "";  // Variable to store saved text when return is hit
    
    
    int total;
    String title;
    int indent = 25;
    int lead = 36;
    boolean go;
    int tt;
    Circ[] Circ1 = new Circ[tt];
    
    void setup() {
      size(850,500);
      smooth();
      f = createFont("Helvetica",22,true);
      for(int i = 0; i < Circ1.length; i++) {
        Circ1[i] = new Circ(width/2, height/2, random(8,14));
      }
    }
    
    void draw() {
      background(0);
      textAlign(LEFT);
      textFont(f, 14);
      fill(255);
      rect(265,20,250,22);
      fill(100);
      text(typing,indent*11,lead);
      fill(255);
      rect(0,indent*11,100,20);
      text("Type your search and press ENTER", indent, lead);
      text(": "+total,width-75,lead);
      textAlign(RIGHT);
      text(saved,width-80,lead);
      fill(255);
      noStroke();
      rect(0,60,width,height-60);
    
      for(int i = 0; i < Circ1.length; i++) {
        Circ1[i].move();
        Circ1[i].display();
        Circ1[i].rollover(mouseX,mouseY);
      }
    }
    
    
    void keyPressed() {
      // If the return key is pressed, save the String and clear it
      if (key == '\n' ) {
        fill(255);
        noStroke();
        rect(0,60,width,height-60);
        saved = typing;
        typing = "";
        getArticleKeywordCount(saved,"2009","2010"); //calling the function from bellow
        // A String can be cleared by setting it equal to ""
        go = true;
        background(255);
        for(int i = 0; i < tt-1; i++) {
          Circ tempc = new Circ(width/2, height/2, random(8,14));
          Circ1 = (Circ[])append ( Circ1, tempc);
        }
      } 
      else 
      {
        //concatenate the String
        // Each character typed by the user is added to the end of the String variable.
        typing = typing + key;
      }
    }
    
    int getArticleKeywordCount(String searchWord, String beginDate, String endDate) { //Method (function) to retrieve articles
      String request = baseURL + "?query="+searchWord+"&begin_date="+beginDate+"0101&end_date="+endDate+ "0101&api-key=" + apiKey;
      String result = join(loadStrings( request ),"");
      //    int total = 0;
      //wrap it in a try/catch statement so we catch an exception if something goes wrong
      try {
        JSONObject nytData = new JSONObject(join(loadStrings(request),""));
        JSONArray results = nytData.getJSONArray("results");
        total = nytData.getInt("total");
        tt=total;
    //    String title =nytData.getString("title");
        //    println( "There were " + total + " occurences of "+searchWord+" between "+beginDate+" & "+endDate+"Titles"+title );
        println(results);
      }
      catch(JSONException e) {
        println( "There was an error parsing the JSONObject nytData." );
      }  
      return(total); //the int called for at the beginning of the function
    }// END getArticles function
    
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    Jeremy

    NYTsearch_verySimple

    Add to Faves Me Likey@! 1
    You must login/register to add this sketch to your favorites.

    Enter a keyword for The New York Times article search

    You need to login/register to comment.