Can You Help me with Visualizing Data from an RSS feed?

edited October 2013 in How To...

Hello - I am working with an RSS feed from a website that updates only once a day.

Thus far I have been able to work out the string url, XMLElement/getChild, String/getContent, String/substring, and println. I would like to create an animation that uses a color change from the time that I play the sketch until the time that the RSS feed changes on the next day. At which point I would like to have the animation start again. I have not been able to find a Tutorial that will show me how to use the RSS feed in conjunction with my own visuals as opposed to a news feed or something of that sort. Could someone out there either recommend a tutorial that will help me with this - or suggest an approach to achieving my goal? Thank you!


  • edited October 2013

    Hello - I will try posting again with more detail - perhaps I phrased the title wrong? Below is the code that I have thus far and I am trying to activate a change in an animation when the text after curMoonPhase - changes. The code is below. If anyone could offer any pointers of where to look next for creating an animation I would really appreciate it.

    String url = "http://"; // Remove space after // (messed up by forum)
    XMLElement rss = new XMLElement(this, url);
    XMLElement moonPhaseElement = rss.getChild("channel/item/title");
    String moonPhaseText = moonPhaseElement.getContent();
    String curMoonPhase = moonPhaseText.substring(20);
  • I am trying to activate a change in an animation

    that's the vague bit. also the timing. if this is only going to change once a day that's not, to me, an animation, it's a graphic.

    what are the possible values for curMoonPhase? do you have a complete list?

    put all the possible values in a String array and then you can iterate over them, checking for a match and then do what you want to do, like a big if() statement basically.

  • edited October 2013

    and it's kinda question: in which part of sketch this code will be used? To me "animation" means something what changes quickly, like 20-30 times per second. If you put code to check for the moonphase into draw() then it will be executed ~60times per second. Which means that in 1 minute you will check your moon state 3600 times... ?

    Can you describe in very simple language WHAT you're trying to accomplish?

    By very simple language, I means: describe what you expect to see on the screen. Describe it in simple words, as if you would be explaining it to a 6 year old. ;)

  • An example:

    HashMap<String, PImage> moonPhases = new HashMap<String, PImage>();
    void setup()
      size(500, 500);
      // Map init
      moonPhases.put("Waning Gibbous", loadImage("WG.png"));
      moonPhases.put("Full", loadImage("F.png"));
      // Etc.
      // For testing purpose, make the graphics here
      PGraphics moon = createGraphics(200, 200, JAVA2D);
      moon.ellipse(100, 100, 200, 200);
      moonPhases.put("Full", moon);
      moon = createGraphics(200, 200, JAVA2D);
      moon.arc(100, 100, 200, 200, 0, PI+QUARTER_PI, OPEN);
      moonPhases.put("Waning Gibbous", moon);
    int hour = -1; 
    void draw()
      if (hour != hour())
        hour = hour();
        println("Change in hour: " + hour);
      // Test only, to remove
      if (keyPressed) { curMoonPhase = ""; }
      PImage currentPhase = moonPhases.get(curMoonPhase);
      if (currentPhase == null) // Not found
        currentPhase = moonPhases.get("Full"); // Default, can be something else!
      image(currentPhase, (width - currentPhase.width) / 2, (height - currentPhase.height) / 2);
    String curMoonPhase;
    void readFeed()
      String url = "";
      XML rss = loadXML(url);
      XML moonPhaseElement = rss.getChild("channel/item/title");
      String moonPhaseText = moonPhaseElement.getContent();
      int pos = moonPhaseText.indexOf(": ");
      if (pos >= 0)
        curMoonPhase = moonPhaseText.substring(pos + 2);
        curMoonPhase = moonPhaseText; // In case something changes

    Note that I changed the readFeed() code to work in 2.0...

Sign In or Register to comment.