Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

adding the workshop starter files

  • Loading branch information...
commit 95bb0c63fc2be530ea60e375e54d4f058046ee92 1 parent 1cf79c1
Val Head authored

Showing 32 changed files with 784 additions and 12 deletions. Show diff stats Hide diff stats

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