Source Code. Projects. Nerd Stuff. Art Stuff.

Data

Grabs a randomized joke from the joke repo (XML):
http://itp.nyu.edu/~ck987/sinatra/joke-repo/api.xml

 

[gn_spoiler title="loadXML" open="0" style="1"]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
XML xml;

void setup() {
  size(600, 300);
 
  xml = loadXML("http://itp.nyu.edu/~ck987/sinatra/joke-repo/api.xml");
  textAlign(CENTER);
  println(xml.getChild("rating").getContent());
}

void draw() {
  background(0);
  text(xml.getChild("joke").getContent(), width/2, height/2);
}
[/gn_spoiler]

 

Grabs a joke from the joke repo (JSON):
http://itp.nyu.edu/~ck987/sinatra/joke-repo/api.json

 

[gn_spoiler title="loadJSON" open="0" style="1"]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import org.json.*;
String jokeStr = "";
String jokeAPI = "http://itp.nyu.edu/~ck987/sinatra/joke-repo/api.json";

void setup() {
  size(640, 480);
}

void draw() {
  background(0);
  textAlign(CENTER);
  text(jokeStr, width/2, height/2);
}

void loadJson() {
  String rawJson = join(loadStrings(jokeAPI), '\n');
  println(rawJson);

  JSONObject jObj = new JSONObject(rawJson);
  jokeStr = jObj.getString("joke");
}

void mousePressed() {
  // thread creates a separate process that loads the funciton
  thread("loadJson");
}
[/gn_spoiler]