Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding the workshop starter files

  • Loading branch information...
commit 95bb0c63fc2be530ea60e375e54d4f058046ee92 1 parent 1cf79c1
Val Head authored
Showing with 784 additions and 12 deletions.
  1. +1 −11 .gitignore
  2. +30 −0 01 Helpful Things/LoadingFont/LoadingFont.pde
  3. BIN  01 Helpful Things/LoadingFont/data/ArialMT-48.vlw
  4. +4 −0 01 Helpful Things/PFont_list/PFont_list.pde
  5. +26 −0 01 Helpful Things/UsingAClass/Box.pde
  6. +30 −0 01 Helpful Things/UsingAClass/UsingAClass.pde
  7. BIN  01 Helpful Things/imageLoading/data/tuckerbadge.jpg
  8. +18 −0 01 Helpful Things/imageLoading/imageLoading.pde
  9. BIN  01 Helpful Things/imagePixels/data/tuckerbadge.jpg
  10. +25 −0 01 Helpful Things/imagePixels/imagePixels.pde
  11. +4 −0 02 Loading text/hello.txt
  12. +4 −0 02 Loading text/loadtext02/data/hello.txt
  13. +15 −0 02 Loading text/loadtext02/loadtext02.pde
  14. +1 −0  03 Loading numbers/loadNumbers02/data/nums.txt
  15. +31 −0 03 Loading numbers/loadNumbers02/loadNumbers02.pde
  16. +4 −0 04 Saving Text/repeatMe01/dots.txt
  17. +76 −0 04 Saving Text/repeatMe01/repeatMe01.pde
  18. +84 −0 04 Saving Text/repeatMe02/repeatMe02.pde
  19. +94 −0 04 Saving Text/repeatMe03/repeatMe03.pde
  20. +70 −0 05 YahooWeather/IsItSunny01/IsItSunny01.pde
  21. BIN  05 YahooWeather/IsItSunny01/data/sun.png
  22. BIN  05 YahooWeather/assets/sun.png
  23. BIN  05 YahooWeather/assets/sunny.ai
  24. +65 −0 06 TwitterAPI/TwitterTimeline/Timeline01/Timeline01.pde
  25. BIN  06 TwitterAPI/TwitterTimeline/Timeline01/code/twitter4j-core-2.2.6.jar
  26. +53 −0 06 TwitterAPI/TwitterVS01/Circle.pde
  27. +87 −0 06 TwitterAPI/TwitterVS01/TwitterVS01.pde
  28. BIN  06 TwitterAPI/TwitterVS01/code/twitter4j-core-2.2.6.jar
  29. BIN  06 TwitterAPI/TwitterVS01/data/Avenir-Medium-30.vlw
  30. BIN  07 Spotify API/spotifyAPI01/code/json.jar
  31. +60 −0 07 Spotify API/spotifyAPI01/spotifyAPI01.pde
  32. +2 −1  README.md
View
12 .gitignore
@@ -1,11 +1 @@
-# Build and Release Folders
-bin/
-bin-debug/
-bin-release/
-
-# Other files and folders
-.settings/
-
-# Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties`
-# should NOT be excluded as they contain compiler settings and other important
-# information for Eclipse / Flash Builder.
+.DS_Store
View
30 01 Helpful Things/LoadingFont/LoadingFont.pde
@@ -0,0 +1,30 @@
+/*
+Loading + Displaying a Font. Fun! (and useful!)
+11/17/12 'INPUT' Processing workshop @ hackPittsburgh
+val head
+@vlh
+*/
+
+size(400,400);
+
+//delcare your font var
+PFont f, myFont;
+//load the font
+f = loadFont("ArialMT-48.vlw");
+//specify the font - var and size
+textFont(f, 36);
+//give it a fill
+fill(0);
+//now, finally write some text
+text("some stuff", 10,100);
+
+
+//another way to use fonts based on what's installed on your machine
+//list all the fonts we have available here
+String[] fontList = PFont.list();
+println(fontList);
+
+//use a font from that list
+ myFont = createFont("Zapfino", 58);
+ textFont(myFont, 58);
+ text("avenir", 0, 40);
View
BIN  01 Helpful Things/LoadingFont/data/ArialMT-48.vlw
Binary file not shown
View
4 01 Helpful Things/PFont_list/PFont_list.pde
@@ -0,0 +1,4 @@
+//super helpful, from http://processing.org/reference/PFont.html
+
+String[] fontList = PFont.list();
+println(fontList);
View
26 01 Helpful Things/UsingAClass/Box.pde
@@ -0,0 +1,26 @@
+class Box {
+
+ // a somewhat silly class to show how these class things can come in handy
+ // hopefully your real classes will do more than just draw some rectangles
+
+ color c;
+ int w;
+ int h;
+ int x;
+ int y;
+
+ Box(color tempC, int tempW, int tempH, int tempX, int tempY) {
+ // our Class' contructor, we'll create some temporary variables just to show how this works
+ c = tempC;
+ w = tempW;
+ h = tempH;
+ x =tempX;
+ y = tempY;
+ }
+
+ void display() {
+ // our amazing Box class has a custom method to display itself
+ fill(c);
+ rect(x,y, w, h);
+ }
+}
View
30 01 Helpful Things/UsingAClass/UsingAClass.pde
@@ -0,0 +1,30 @@
+//some colurs we'll use
+color[] palette= {
+ color(180, 0, 157), color(0, 146, 180), color(104, 18, 203), color(74, 198, 83), color(203, 43, 18)
+};
+
+// we're going to create some Boxes, and these are the names we've picked for them
+Box bob;
+Box sally;
+Box tucker;
+
+void setup() {
+ size(400,400);
+ background(255);
+ noStroke();
+
+ //we'll create three new Boxes, each with their own properies
+ bob = new Box(palette[2], 200, 50, 100, 100);
+ bob.display();
+
+ sally = new Box(palette[0], 50, 50, 10,10);
+ sally.display();
+
+ tucker = new Box(palette[3], 100, 20, 300, 300);
+ tucker.display();
+}
+
+void draw() {
+
+
+}
View
BIN  01 Helpful Things/imageLoading/data/tuckerbadge.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
18 01 Helpful Things/imageLoading/imageLoading.pde
@@ -0,0 +1,18 @@
+/*
+Loading an image, yay!
+11/17/12 'INPUT' Processing workshop @ hackPittsburgh
+val head
+@vlh
+*/
+
+size(600,400);
+
+//declare and assign our image variable
+PImage b;
+b = loadImage("tuckerbadge.jpg");
+
+//display our image and center it along the x axis
+image(b, width/2 - b.width/2, 0);
+
+//the width of our image
+println(b.width);
View
BIN  01 Helpful Things/imagePixels/data/tuckerbadge.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
25 01 Helpful Things/imagePixels/imagePixels.pde
@@ -0,0 +1,25 @@
+/*
+Grabbing a random pixel from our image
+11/17/12 'INPUT' Processing workshop @ hackPittsburgh
+val head
+@vlh
+*/
+
+size(600,400);
+
+//declare and assign our image variable
+PImage b;
+b = loadImage("tuckerbadge.jpg");
+
+//display our image and center it along the x axis
+image(b, width/2 - b.width/2, 0);
+
+//the width of our image
+println(b.width);
+
+//draw a square using a colour from the image
+color col = b.pixels[round(random(0, b.pixels.length))];
+println(b.pixels.length);
+noStroke();
+fill(col);
+rect(10,10,100,100);
View
4 02 Loading text/hello.txt
@@ -0,0 +1,4 @@
+Hello future self
+How are things looking 5 minutes from now?
+Yeah
+That's what I though
View
4 02 Loading text/loadtext02/data/hello.txt
@@ -0,0 +1,4 @@
+Hello future self
+How are things looking 5 minutes from now?
+Yeah
+That's what I though
View
15 02 Loading text/loadtext02/loadtext02.pde
@@ -0,0 +1,15 @@
+/*
+Basic Loading Text Example
+11/17/12 'INPUT' Processing workshop @ hackPittsburgh
+val head
+@vlh
+*/
+
+//create an array of Strings to store our lines in, and load in the file
+String[] lines = loadStrings("hello.txt");
+//tell me how many lines there are in this file
+println("there are " + lines.length + " lines");
+//but what are those lines, huh?
+for (int i=0; i < lines.length; i++) {
+ println(lines[i]);
+}
View
1  03 Loading numbers/loadNumbers02/data/nums.txt
@@ -0,0 +1 @@
+50,100,9,200,40,60,85,22,18,25
View
31 03 Loading numbers/loadNumbers02/loadNumbers02.pde
@@ -0,0 +1,31 @@
+/*
+Basic Loading Numbers Example!
+11/17/12 'INPUT' Processing workshop @ hackPittsburgh
+val head
+@vlh
+*/
+
+int[] data;
+
+void setup() {
+ size(200,400);
+
+ //even though it's numbers, we load it in as strings first.
+ String[] things = loadStrings("nums.txt");
+ //convert our string into an array of integers
+ data = int(split(things[0], ','));
+
+ println(data);
+
+}
+void draw() {
+
+ background(255);
+ noStroke();
+
+ for (int i=0; i < data.length; i++) {
+ fill(data[i]);
+ rect(i*20,0,20,data[i]);
+ }
+}
+
View
4 04 Saving Text/repeatMe01/dots.txt
@@ -0,0 +1,4 @@
+258 108
+323 304
+210 300
+378 239
View
76 04 Saving Text/repeatMe01/repeatMe01.pde
@@ -0,0 +1,76 @@
+/*
+Plotting, saving and reading back position values - Repeat Me
+11/17/12 'INPUT' Processing workshop @ hackPittsburgh
+val head
+@vlh
+*/
+
+int[] xlist = new int[0];
+int[] ylist = new int[0];
+
+String[] savedPos;
+
+
+int radius = 20; //size of our dots
+
+
+void setup() {
+ size(600,600);
+ smooth();
+ background(0);
+ println("-----");
+}
+
+
+void draw() {
+ noStroke();
+ fill(255);
+
+}
+
+void mousePressed() {
+ //draw our dot
+ ellipse(mouseX, mouseY, radius, radius);
+ //save the positions
+ xlist = append(xlist, mouseX); //add a value to our xlist array
+ ylist = append(ylist, mouseY);
+}
+
+
+void keyPressed() {
+ if (key == 's'){
+ String[] dotPos = new String[xlist.length]; //new array with the same length as xlist
+ for (int i = 0; i < xlist.length; i++) {
+ dotPos[i] = xlist[i] + "\t" + ylist[i];
+ }
+
+ saveStrings("dots.txt", dotPos); //filename, data
+// exit(); // Stop the program
+
+ drawDots();
+ }
+
+}
+
+void drawDots() {
+ //erase the screen
+ fill(random(0,255));
+ rect(0,0,width, height);
+ //set a new colour for our drawn on dots
+ fill(255,0,255);
+ savedPos = loadStrings("dots.txt");
+ //loop through
+ //convert our string into an array of integers
+ //but we've got both lines and tabs to deal with
+ for (int i =0; i < savedPos.length; i++) {
+ //split each line with tab as delimiter and save into a new array
+ int [] posData = int(split(savedPos[i], '\t'));
+ if (posData.length ==2) {
+ int x = posData[0];
+ int y = posData[1];
+ ellipse(x,y,radius, radius);
+ }
+ ;
+ }
+
+}
View
84 04 Saving Text/repeatMe02/repeatMe02.pde
@@ -0,0 +1,84 @@
+/*
+Plotting, saving and reading back position values - Repeat Me
+11/17/12 'INPUT' Processing workshop @ hackPittsburgh
+val head
+@vlh
+*/
+
+//make these ArrayLists for more flexibility, yay!
+
+ArrayList xlist = new ArrayList();
+ArrayList ylist = new ArrayList();
+
+String[] savedPos;
+
+String currentFile;
+
+int radius = 20; //size of our dots
+
+
+void setup() {
+ size(600,600);
+ smooth();
+ background(0);
+ println("-----");
+}
+
+
+void draw() {
+ noStroke();
+ fill(255);
+
+}
+
+void mousePressed() {
+ //draw our dot
+ ellipse(mouseX, mouseY, radius, radius);
+ //save the positions
+ xlist.add (mouseX); //add a value to our xlist array
+ ylist.add(mouseY);
+}
+
+
+void keyPressed() {
+ if (key == 's'){
+ String[] dotPos = new String[xlist.size()]; //new array with the same length as xlist
+ for (int i = 0; i < xlist.size(); i++) {
+ dotPos[i] = xlist.get(i) + "\t" + ylist.get(i);
+ //now that we've saved them, remove them from the arraylist to clear the values
+ }
+
+ String timeStamp = hour() + "_"+ minute() + "_" + second();
+ currentFile = "dots"+timeStamp +".txt";
+ saveStrings(currentFile, dotPos); //filename, data
+ xlist.clear();
+ ylist.clear();
+// exit(); // Stop the program
+
+ drawDots();
+ }
+
+}
+
+void drawDots() {
+ //erase the screen
+ fill(0);
+ rect(0,0,width, height);
+ //set a new colour for our drawn on dots
+ fill(255,0,255);
+ savedPos = loadStrings(currentFile);
+ //loop through
+ //convert our string into an array of integers
+ //but we've got both lines and tabs to deal with
+ for (int i =0; i < savedPos.length; i++) {
+ //split each line with tab as delimiter and save into a new array
+ int [] posData = int(split(savedPos[i], '\t'));
+ if (posData.length ==2) {
+ int x = posData[0];
+ int y = posData[1];
+ ellipse(x,y,radius, radius);
+ }
+ ;
+ }
+
+}
View
94 04 Saving Text/repeatMe03/repeatMe03.pde
@@ -0,0 +1,94 @@
+/*
+Plotting, saving and reading back position values - Repeat Me
+11/17/12 'INPUT' Processing workshop @ hackPittsburgh
+val head
+@vlh
+*/
+
+//make these ArrayLists for more flexibility, yay!
+
+ArrayList xlist = new ArrayList();
+ArrayList ylist = new ArrayList();
+
+String[] savedPos;
+
+String currentFile;
+
+Boolean playback = false;
+
+int radius = 20; //size of our dots
+void setup() {
+ size(600,600);
+ smooth();
+ background(0);
+ noStroke();
+
+
+ frameRate(12);
+}
+
+void draw() {
+ if (playback) {
+ drawDots();
+ }else {
+ fill(255);
+ }
+
+}
+
+void mousePressed() {
+ //stop playback
+ playback= false;
+
+ //draw our dot
+ ellipse(mouseX, mouseY, radius, radius);
+ //save the positions
+ xlist.add (mouseX); //add a value to our xlist array
+ ylist.add(mouseY);
+}
+
+
+void keyPressed() {
+ if (key == 's'){
+ String[] dotPos = new String[xlist.size()]; //new array with the same length as xlist
+ for (int i = 0; i < xlist.size(); i++) {
+ dotPos[i] = xlist.get(i) + "\t" + ylist.get(i);
+ }
+
+
+ String timeStamp = hour() + "_"+ minute() + "_" + second();
+ currentFile = "dots"+timeStamp +".txt";
+ saveStrings(currentFile, dotPos); //filename, data
+ //clear our position lists
+ xlist.clear();
+ ylist.clear();
+// exit(); // Stop the program
+
+ playback = true;
+
+ }
+
+}
+
+void drawDots() {
+ //erase the screen
+ fill(0);
+ rect(0,0,width, height);
+ //set a new colour for our drawn on dots
+ fill(255,0,255);
+ savedPos = loadStrings(currentFile);
+ //loop through
+ //convert our string into an array of integers
+ //but we've got both lines and tabs to deal with
+ for (int i =0; i < savedPos.length; i++) {
+ //split each line with tab as delimiter and save into a new array
+ int [] posData = int(split(savedPos[i], '\t'));
+ if (posData.length ==2) {
+ int x = posData[0];
+ int y = posData[1];
+ ellipse(x,y,radius, radius);
+ }
+ ;
+ }
+
+}
View
70 05 YahooWeather/IsItSunny01/IsItSunny01.pde
@@ -0,0 +1,70 @@
+/*
+Is it Sunny in Pittsburgh Right Now?
+11/17/12 'INPUT' Processing workshop @ hackPittsburgh
+val head
+@vlh
+*/
+
+// yahoo weather library for Processing
+// http://www.onformative.com/lab/google-weather-library-for-processing/
+
+import com.onformative.yahooweather.*;
+
+YahooWeather weather;
+int updateIntervallMillis = 30000;
+
+String descriptionText;
+PImage sun;
+
+PFont gothlight;
+
+void setup() {
+ size(700, 400);
+
+ smooth();
+ fill(255);
+
+ sun = loadImage("sun.png");
+
+ // 2473224 = WOEID of Pittsburgh
+ weather = new YahooWeather(this, 2473224, "c", updateIntervallMillis);
+
+}
+
+void draw() {
+ weather.update();
+
+ background(0);
+// add our title
+ textFont(createFont("Gotham-Bold", 28));
+ text("Is It Sunny In Pittsburgh Right Now?", width/2, 60);
+ textAlign(CENTER);
+
+ //figure out what we think of this weather
+ assesWeather(weather.getWeatherConditionCode());
+}
+
+
+void assesWeather(int code) {
+ println(code);
+ //codes we're pretty sure will mean there's sun
+ if (code == 34 || code == 30 || code == 32 || code == 36 || code == 44) {
+ //show YES conditions
+ descriptionText = "Yes! Can you believe it?";
+ image(sun, width/2 - sun.width/2, 80);
+
+ } else if (code == 27 || code == 29 || code == 31 || code == 33) {
+ // codes that are likely to actually be night time
+ descriptionText = "Of course not, it's night!";
+
+ }else {
+ //It's likely neither sunny or night time so, show NO conditions
+ descriptionText = "Sunniness seems very unlikely right now";
+ }
+
+ //in any case, we're going to show this text
+ text(descriptionText, width/2, 320);
+ textAlign(CENTER);
+
+}
+
View
BIN  05 YahooWeather/IsItSunny01/data/sun.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  05 YahooWeather/assets/sun.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  05 YahooWeather/assets/sunny.ai
Binary file not shown
View
65 06 TwitterAPI/TwitterTimeline/Timeline01/Timeline01.pde
@@ -0,0 +1,65 @@
+/*
+Accessing your twitter timeline with the Twitter REST API and Twitter4J
+11/17/12
+'INPUT' Processing workshop @ hackPittsburgh
+val head
+@vlh
+*/
+
+
+//using twitter4J
+//https://github.com/yusuke/twitter4j/
+
+ResponseList statuses;
+
+int count = 0;
+
+void setup() {
+size(900,400);
+
+
+ConfigurationBuilder cb = new ConfigurationBuilder();
+cb.setOAuthConsumerKey("");
+cb.setOAuthConsumerSecret("");
+cb.setOAuthAccessToken("");
+cb.setOAuthAccessTokenSecret("");
+
+Twitter twitter = new TwitterFactory(cb.build()).getInstance();
+
+
+ try {
+ statuses = twitter.getMentions();
+//statuses = twitter.getUserTimeline();
+ for(int i=0; i<statuses.size(); i++) {
+ Status status = (Status)statuses.get(i);
+// println(status.getUser().getName() + ": " + status.getText());
+ }
+
+
+ } catch(TwitterException e) {
+ println("Get timeline: " + e + " Status code: " + e.getStatusCode());
+ }
+}
+
+
+void draw() {
+
+ if (count%250 ==0 ) {
+
+ fill(0);
+ rect(0,0,width,height);
+
+ //pick a random status from the list we have
+ int i = (frameCount % statuses.size());
+ Status tweet = (Status)statuses.get(i);
+ String tweetText = tweet.getUser().getName() + ": " + tweet.getText();
+
+ //draw it on screen
+ fill(255);
+ text(tweetText, 20, 100, 400, 200);
+ textAlign(CENTER);
+ }
+
+ count++;
+
+}
View
BIN  06 TwitterAPI/TwitterTimeline/Timeline01/code/twitter4j-core-2.2.6.jar
Binary file not shown
View
53 06 TwitterAPI/TwitterVS01/Circle.pde
@@ -0,0 +1,53 @@
+class Circle {
+
+ float d;
+ float xpos;
+ float ypos;
+ color c;
+
+ String playerWord;
+ String score;
+
+ Circle(String tempPlayer, float tempScore, float tempR, color tempC, int tempX, int tempY) {
+ playerWord = tempPlayer;
+
+ score = str(tempScore);
+ d = tempR;
+ c = tempC;
+ xpos = tempX;
+ ypos = tempY;
+
+ display();
+ }
+
+ void display() {
+ fill(c);
+ pushMatrix();
+ translate(xpos,ypos);
+ ellipse(0, 0,d, d);
+
+ fill(255);
+ //now, finally write some text
+
+ text(playerWord, 0,0);
+ textAlign(CENTER, CENTER);
+ popMatrix();
+ }
+
+ void update() {
+
+ }
+
+ void pressed(int mx, int my) {
+ if (dist(mx,my,xpos,ypos) < d/2) {
+ pushMatrix();
+ translate(xpos,ypos);
+ text(score, 0,150);
+ textAlign(CENTER);
+ popMatrix();
+ println("pressed");
+ }
+
+ }
+
+}
View
87 06 TwitterAPI/TwitterVS01/TwitterVS01.pde
@@ -0,0 +1,87 @@
+
+/*
+A silly Twitter battle pitting one "word" against another
+11/17/12 'INPUT' Processing workshop @ hackPittsburgh
+val head
+@vlh
+*/
+
+ArrayList<String> player01list = new ArrayList();
+ArrayList<String> player02list = new ArrayList();
+
+String player01 = "tapp";
+String player02 ="mop";
+
+float total01;
+float total02;
+
+ Circle c1, c2;
+
+color[] palette= {
+
+ color(180, 0, 157), color(0, 146, 180), color(104, 18, 203), color(74, 198, 83), color(203, 43, 18)
+};
+
+PFont f, myFont;
+
+void setup() {
+
+ size(800, 400);
+ background(0);
+ smooth();
+
+ //load the font
+ f = loadFont("Avenir-Medium-30.vlw");
+ //specify the font - var and size
+ textFont(f, 30);
+
+ ConfigurationBuilder cb = new ConfigurationBuilder();
+ cb.setOAuthConsumerKey("");
+ cb.setOAuthConsumerSecret("");
+ cb.setOAuthAccessToken("");
+ cb.setOAuthAccessTokenSecret("");
+
+ Twitter twitter = new TwitterFactory(cb.build()).getInstance();
+
+ //run our first player
+ Query query01 = new Query(player01);
+ try {
+ QueryResult result01 = twitter.search(query01);
+ ArrayList tweets01 = (ArrayList) result01.getTweets();
+ println("total player 1 tweets: " + tweets01.size());
+ total01 = tweets01.size();
+ }
+ catch (TwitterException te) {
+ println("Couldn't connect: " + te);
+ };
+
+ //run our second player
+ Query query02 = new Query(player02);
+ try {
+ QueryResult result02 = twitter.search(query02);
+ ArrayList tweets02 = (ArrayList) result02.getTweets();
+ println("total player 2 tweets: " + tweets02.size());
+ total02 = tweets02.size();
+ }
+ catch (TwitterException te) {
+ println("Couldn't connect: " + te);
+ };
+
+
+ float score01 = map(total01, 0, 15, 0, 200);
+ float score02 = map(total02, 0, 15, 0, 200);
+
+ c1 = new Circle(player01, total01, score01, palette[int(random(4))], 200, 200);
+ c2 = new Circle(player02, total02, score02, palette[int(random(4))], 600, 200);
+
+}
+
+void draw() {
+
+}
+
+void mousePressed () {
+ c1.pressed(mouseX, mouseY);
+ c2.pressed(mouseX, mouseY);
+}
+
View
BIN  06 TwitterAPI/TwitterVS01/code/twitter4j-core-2.2.6.jar
Binary file not shown
View
BIN  06 TwitterAPI/TwitterVS01/data/Avenir-Medium-30.vlw
Binary file not shown
View
BIN  07 Spotify API/spotifyAPI01/code/json.jar
Binary file not shown
View
60 07 Spotify API/spotifyAPI01/spotifyAPI01.pde
@@ -0,0 +1,60 @@
+/*
+A start on charting the Spotify popularity of your favourite band :)
+11/17/12 'INPUT' Processing workshop @ hackPittsburgh
+val head
+@vlh
+*/
+
+import org.json.*;
+
+float [] pop = new float[100];
+//some colours to use
+color[] colors = {#FF0000, #00FF00, #0000FF, #FF3300, #FF9900};
+int c = 0;
+
+void setup() {
+ size(400,400);
+
+ try {
+ String url = "http://ws.spotify.com/search/1/track.json?q=sleater%20kinney";
+ JSONObject data = new JSONObject(join(loadStrings(url), ""));
+ JSONArray entries = data.getJSONArray("tracks");
+
+ for (int i = 0; i < entries.length(); i++) {
+ JSONObject entry = entries.getJSONObject(i);
+ JSONObject album = entry.getJSONObject("album");
+
+ String name = entry.getString("name");
+ String aname = album.getString("name");
+ double popularity = entry.getDouble("popularity");
+ //add it to the array of popularity numbers
+ pop[i] = (float)popularity; //convert our fancy double to a float
+
+ //just to see if we've got all the data we think we have
+ println(popularity + "\t" + name+ ", " + aname);
+ }
+ }
+
+ catch (JSONException e) {
+ println(e.toString());
+ }
+
+
+
+}
+
+void draw() {
+ noStroke();
+ for (int i=0; i < pop.length; i++) {
+
+ if (c < colors.length-1) {
+ c++;
+ }else {
+ c=0;
+ }
+ fill(colors[c]);
+ float f = (float)pop[i];
+ rect(i*20,height,20,-1*f*200);
+ }
+
+}
View
3  README.md
@@ -1,4 +1,5 @@
InputProcessingWorkshop
=======================
-Files from the November 2012 HackPIttsburgh Processing workshop
+Files from the November 2012 HackPIttsburgh Processing workshop
+http://www.hackpittsburgh.org/intermediate-processing-class-inputs-getting-data-into-processing

0 comments on commit 95bb0c6

Please sign in to comment.
Something went wrong with that request. Please try again.