Category: Uncategorized

Minnar – “I wish I could stop time”

People don’t really mean ‘I wish I could stop time’ in a literal sense; what they actually mean is ‘I wish this moment could last forever’ or ‘I want to be able to do this or that.’ I’m interested in exploring what it means when we can literally stop a clock from moving forward. The act of actually stopping time forces us to understand how futile and pointless it is for us to want to stop time when time is just a measure we believe dictates how our lives move. In reality, our perception of time slows or speeds depending on how we choose to make use of our time.

Using a relay, the red clock stops time whenever someone in the world tweets something containing the phrase “stop time.” The stop lasts a quarter of a second per character of the tweet (the stops range from 10 seconds to a couple minutes). Displayed next to the black clock at the accurate time, throughout the day the red clock slows to reveal the time we actually lose through wishing time would stop.


// Checks your account for a new tweet, parses it for a value (in the first "word"), and sends this value to an arduino
 
import twitter4j.conf.*;
import twitter4j.internal.async.*;
import twitter4j.internal.org.json.*;
import twitter4j.internal.logging.*;
import twitter4j.http.*;
import twitter4j.api.*;
import twitter4j.util.*;
import twitter4j.internal.http.*;
import twitter4j.*;
import processing.serial.*;
 
// HEY! GET YER OWN KEYS FROM: https://dev.twitter.com/apps/new
static String OAuthConsumerKey    = "9Qh0vcGVWo6CodugNOEX5A";
static String OAuthConsumerSecret = "WHVH4bkHDEN0x5DlkwkbZntARTJ7QkIhdPifGMfge0";
static String AccessToken         = "987214699-oyxzLFl6yqzTUMuA9RggpAHoZQtFfXR9lJxHutIi";
static String AccessTokenSecret   = "HRmGV4fjpbbVeZyMNsSAeuleTGKmD31FBCj1DXZp8";
 
Serial myArduinoSerial;
Twitter myTwitter = new TwitterFactory().getInstance();
 
String  myQueryWord = "\"stop time\"";  
long    previousIdOfTweetContainingQuery = 0;
int     tweetContainingQueryLength;
 
//===========================================================================
void setup() {
  size();
  size(125, 125);
  frameRate(10);
  background(0);
  println(Serial.list());
  String arduinoPort = Serial.list()[0];
  myArduinoSerial = new Serial(this, arduinoPort, 9600);
  loginTwitter();
}
 
//===========================================================================
void loginTwitter() {
  myTwitter.setOAuthConsumer (OAuthConsumerKey, OAuthConsumerSecret);
  AccessToken accessToken = new AccessToken(AccessToken, AccessTokenSecret);
  myTwitter.setOAuthAccessToken(accessToken);
}
 
//===========================================================================
void draw() {
 
  try {
    println ("Searching.... Current time = " + hour() + ":" + minute() + ":" + second()); 
    Query query = new Query(myQueryWord);
    query.setRpp (5); // how many results to fetch
    QueryResult result = myTwitter.search(query);
 
    ArrayList tweetsContainingQuery = (ArrayList) result.getTweets();
    if (tweetsContainingQuery.size() > 0) {
      Tweet mostRecentTweetContainingQuery = (Tweet) tweetsContainingQuery.get(0);
      long mostRecentTweetContainingQueryId = mostRecentTweetContainingQuery.getId();
 
      if (previousIdOfTweetContainingQuery == 0) {
        previousIdOfTweetContainingQuery = mostRecentTweetContainingQueryId;
      }
      if (mostRecentTweetContainingQueryId != previousIdOfTweetContainingQuery) {
        // yay! someone has just tweeted our favorite word!
        previousIdOfTweetContainingQuery = mostRecentTweetContainingQueryId;
        myArduinoSerial.write(1); // HERE IT IS!
          int pauseTime = (tweetContainingQueryLength * 250);
        delay(pauseTime);
        // print out the new tweet, for fun. 
        String user = mostRecentTweetContainingQuery.getFromUser();
        String msg = mostRecentTweetContainingQuery.getText();
        tweetContainingQueryLength = msg.length();
        Date d = mostRecentTweetContainingQuery.getCreatedAt();
        println("Tweet by " + user + " at " + d + ": " + msg + "Character Length = " + tweetContainingQueryLength);
      } else {
        myArduinoSerial.write(0);
    }
    }
 
    /*
    // Indicentally, you can also list all of the most recent tweets containing that search term. Fun!
    for (int i=0; i< tweetsContainingQuery.size(); i++) {
      Tweet t = (Tweet) tweetsContainingQuery.get(i);
      String user = t.getFromUser();
      String msg = t.getText();
      Date d = t.getCreatedAt();
      println("Tweet by " + user + " at " + d + ": " + msg);
    }
    println("--------------------");
    */
 
  }
  catch (TwitterException te) {
    println("Error connecting to Twitter: " + te);
  };
 
  delay (13000); 
}
void setup()
{
  // initialize the serial communication:
  Serial.begin(9600);
  pinMode(8, OUTPUT);
}
 
void loop() {
  // check if data has been sent from the computer:
  if (Serial.available()) {
    byte isOn = Serial.read();
    if (isOn == 1){
      digitalWrite(8, HIGH);
    } else {
      digitalWrite(8, LOW);
  }
}
}

Luo Yi Tan – Final Project

For my final project, I made a game rewarder.

I wanted to make some sort of game, where a machine dispenses some kind of reward whenever you beat it. Pavlovian, some would say.

In the game, you move a small square with your mouse, and click to shoot. If you shoot a big M&M, a smaller M&M will fall from it. The goal of the game is to collect as many little M&Ms as possible.

Here is a screenshot of the game:

The game itself is made in Processing. It wasn’t too hard to implement, but getting the game logic down needed some work, as I have never coded a game from scratch before. The highscore is read and saved in a txt file in the Processing folder.

You can see it in action here:

In the beginning, I designed a box to laser cut, but I accidentally messed up the measurements of the box. So, I improvised, using a cardboard box I had lying around and a garden hose. It turned out well, surprisingly enough. The gear that dispenses the candy was laser cut, moved by two other gears that are connected to a servo. This is controlled by an Arduino, which reads a value from Processing that tells it whether a player has beat the high score or not.

The mechanism is pretty simple:

This is the fritzing diagram:

Extra ideas I had but didn’t have time to do: Dispensing something undesirable when you don’t beat the high score,  and allowing the user to take a picture of their face and put it on the player character.

The Processing code is rather long and also split up into several files, so I have uploaded it on mediafire as a zip file.

http://www.mediafire.com/?o6mwvd2il11aa24

The Arduino code is pretty straightfoward, it simply checks if a signal that the player has beat the high score is sent from Processing:

#include 
Servo servo1;
 
void setup()
{
  servo1.attach(9);
  servo1.write(90);
  Serial.begin(9600);
}
 
void loop() {
 
  // check if data has been sent from the computer:
  if (Serial.available()) {
 
    // read the most recent byte (which will be from 0 to 255):
    byte pos = Serial.read();
 
    // move a servo and RELEASE CANNDEH
    if (pos == 1) {
      servo1.write(0);
      delay(3000);
      servo1.write(90);
      delay(1000);
      //servo1.detach();
    }
  }
 
}

Last assignment, Josh Lopez-Binder

Because my initial idea failed (an attempt to use nitinol muscles to make motion) I made a revision of the last project.  The goal was to make a mechanism that somehow caused a a wave to propagate down a chain. The chain was constructed from links that all had small pegs.  These pegs limited the maximum and minimum angles that the neighboring link could rotate to.

While playing with the chain I found that a curled section could traverse the length of the chain when gravity pulled on it.  To replicated this motion was simple: I attached a motor with a few gears to the first link.  As the link rotates it pulls its neighbors into a curve.  This curve, when it has accumulated enough links and can overcome friction, propagates down the chain, similar to the jacobs ladder toy.

 
 
 
 
int motor = 13;
int switchPin = 2;
 
float minTime = 30;
float maxTime = 1000;
int counter = 0;
boolean runMotor = false;
 
void setup(){
  Serial.begin(9600);
  pinMode(motor, OUTPUT);
  pinMode(switchPin, INPUT);
 
}
 
void loop(){
  int switchState;
  switchState = digitalRead(switchPin);
  //currentSwitchVal = digitalRead(switchPin);
  if(switchState == LOW){
    counter ++;
  }else{
    if(counter>minTime && counter<maxTime){
      runMotor = !runMotor;
      counter = 0;
    }
  }
 
  Serial.println(counter);
 
  if(runMotor){
    digitalWrite(LED, HIGH);
    digitalWrite(motor,HIGH);
  } else{
    digitalWrite(LED,LOW);
    digitalWrite(motor,LOW);
  }
 
}

Connie – Final Project

This project features a lovely, be-jeweled turd that talks. The LEDs are synced with the audio to create the illusion that the turd is, in fact, do the talking. I had originally hoped to make this as an example of how people say things that are insubstantial and amount to basically a pile of crap. Though now looking at it the poop seems to become a character of its own – that may one day rise above its state of abject shit and evolve into the most fabulous poo that ever pooped.

A Shitty Spiel from Connie D on Vimeo.

The audio file was originally played in processing where the values were then sent to Arduino.

Processing:

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import processing.serial.*;
Serial myArduinoSerial;
int valueToSend;
 
import ddf.minim.*;
Minim minim;
AudioPlayer diatribe;
 
PImage goldenpoop;
 
void setup() { 
  size(249, 188);
  goldenpoop = loadImage("goldenpoop.jpg");
 
  minim = new Minim(this);
 
  diatribe = minim.loadFile("poopy.mp3");
 
  float vol = diatribe.getVolume();
 
  println(Serial.list());
 
  myArduinoSerial = new Serial (this, Serial.list()[0], 9600);
}
 
void draw() {
 
  image (goldenpoop, 0, 0);
 
  AudioBuffer theBuf = diatribe.mix;
  float vol = theBuf.level();
  float convertedVol = map(vol, 0, 1, 0, 255);
 
  valueToSend = (int)convertedVol;
 
  vol = diatribe.getVolume();
  println("volume: " + valueToSend);
 
  myArduinoSerial.write(valueToSend);
}
 
void mousePressed() {
  diatribe.rewind();
  diatribe.play();
}
 
void stop() {
  diatribe.close();
  minim.stop();
  super.stop();
}

 

Arduino:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
const int leds[ ] = {
  3, 5, 6, 9, 10, 11};
 
 
void setup() {
  // initialize the serial communication:
  Serial.begin(9600);
  for (int i=0; i< 6; i++){
    pinMode (leds[i], OUTPUT);
  }
}
 
void loop() {
  byte brightness;
 
  if (Serial.available()) {
    brightness = Serial.read();
 
    for (int i=0; i<6; i++){
      analogWrite(leds[i], brightness);
    }
  }
}

Oliver – Final Project

The Different Rainbows of the Instagram LGBT Rainbow

My project explores the LGBT community by means of social media, Instagram in particular, and employs color mapping to determine which colors are used most often in photos of each facet of LGBT. To gather data, I used IFTTT to save all photos with a particular hashtag to a folder in my Dropbox. For example:

I then wrote code a color-mapping algorithm in Processing, as well as a user interface with six functions. My color-mapping algorithm looks at the HSB color values of each pixel of each photograph. If the saturation and brightness are within certain ranges, the pixel is classified as black, white, or grey. If the hue, saturation and brightness are within certain other ranges, the pixel is classified as brown or as “white people color.” If the pixel does not fall into any of those categories, the algorithm finds the closest hue (out of 8 hues that I chose) and puts the pixel in that category. Then the pixels colors are aggregated within each category, and I calculate what percentage of the total pixels in each category are each color. Screens 1 and 2 visualize the color distributions of each category:

       

Screen 1 shows the color distribution with a large sample size (several thousand photos in each category), and Screen 2 shows the color distribution of only the most recent 50 photos in each category. With the large sample size, we see that most of the categories have nearly identical color distributions, with the transgender category being visibly different.

Screen 3 shows very small versions of the most recent 140 photos in each category. Here we can begin to see why the color distributions differ. Just at first glance, it seems that in the transgender category has more images that have a white background and text in the foreground, and comparatively less photos of people than the other categories.

Screen 4 shows a slideshow of photos from the collection, chosen randomly. Looking into all of the faces is almost haunting. The photos are beautiful, sad, random. Screen 5 shows photos randomly from the collection, with a large image of my color-mapping algorithm applied to the photo and a small image of the original photo.

       

Screen 6 is not functional in this prototype, but would essentially allow users to tag photos with different identity categories (gay, lesbian, etc.), sentiments (happy, sad, etc.), or to identify what is in the photo (person, object, etc.). With this application of crowd-sourcing, tagging data could be collected and then used to classify the photos in more ways than just their original hashtags. The photos would then be searchable in several ways (i.e. “show me pictures of sad bisexual people”).

This project taught me quite a bit about gathering and analyzing social media data, user-interface design, color, and algorithm development, and challenged my programming skills. What it’s still lacking is a well-defined “what’s at stake” claim.

Code:

 
/////////////////////////////////////////////////////////////////
// The Different Rainbows of the Instagram LGBT Rainbow        //
// Copyright December 2012                                     //
// created by Oliver Haimson (oliverhaimson@gmail.com)         //
// 67-210 - Electronic Media Studio 2 - Prof. Golan Levin      //
// Final Project                                               //
/////////////////////////////////////////////////////////////////
 
float [] hues = {
10, // red
30, // orange
60, // yellow
120, // green
195, // light blue
240, // blue
280, // violet
330, // pink
345, // red
};
 
int [][] colors = {
{10,360,360},
{30,360,360},
{60,360,360},
{120,360,360},
{195,360,360},
{240,360,360},
{280,360,360},
{330,360,360},
{345,360,360},
{20,104,316},
{40,360,130},
{0,0,360},
{0,0,180},
{0,0,0}
};
 
String [] button5Pics = {"button5a.png","button5b.png","button5c.png",
"button5d.png","button5e.png","button5f.png","button5g.png",
"button5h.png","button5i.png","button5j.png","button5k.png",
"button5l.png","button5m.png","button5n.png","button5o.png",
"button5p.png","button5q.png","button5r.png","button5s.png",
"button5t.png","button5u.png","button5v.png","button5w.png"};
 
String [] folders;
String [] labels = {"#lesbian","#gay","#bi","#transgender","#lgbt"};
 
// 5 folders, 14 colors
int [][] colorDistr = new int [5][14];
float [][] percents = new float [5][14];
float [][] savedData = new float [5][14];
 
PFont font;
PImage insta, loading, button1, button2, button3, button4, button5,
button6;
 
int phase;
Boolean isLoading, slideshow, loadAllPhotos, button4Switch,
button5Switch;
 
void setup() {
smooth();
colorMode(HSB, 360);
size(700, 775);
background(210,227,180);
font=createFont("Helvetica-Bold", 48);
insta = loadImage("insta.jpg");
button1 = loadImage("button1.png");
button2 = loadImage("button2.png");
button3 = loadImage("button3.png");
button6 = loadImage("button6.png");
loading = loadImage("loading.gif");
phase = 100;
isLoading = false;
slideshow = false;
loadAllPhotos = false;
button4Switch = true;
button5Switch = true;
File dir = new File("/Users/oliverhaimson/Dropbox/Processing/project4/data");
folders = subset(dir.list(), 1,5);
//loadAllPhotos();
 
}
 
void loadData() {
for (int m=0; m<folders.length; m++) {
String [] data = loadStrings("Array"+m);
for (int n=0; n<data.length; n++) {
savedData[m][n] = float(data[n]);
}
}
}
 
void saveData() {
String [][] strPercents = new String [5][14];
for (int m=0; m<folders.length; m++) {
strPercents[m] = str(percents[m]);
saveStrings("Array"+m, strPercents[m]);
println(strPercents[m]);
}
}
 
void loadAllPhotos() {
loadAllPhotos=true;
loadPhotos();
drawPhotos();
loadAllPhotos=false;
}
 
void draw() {
if (phase==100) {
drawStartScreen();
}
else if (phase==1) {
loadData();
drawSavedColorData();
}
else if (phase==2) {
loadPhotos();
}
else if (phase==3) {
drawPhotos();
}
else if (phase==4) {
randomPic();
}
else if (phase==5) {
randomPicColors();
}
else if (phase==6) {
evaluatePics();
}
}
 
void evaluatePics() {
background(210,227,180);
drawTitle();
drawBackButton();
fill(0,0,0);
rect(0,25,width,750);
int folderNum = int(random(5));
File innerDir = new File("/Users/oliverhaimson/Dropbox/Processing/project4/data/"+folders[folderNum]);
String[] photos = innerDir.list();
int photoNum = int(random(photos.length));
PImage photo = loadImage(folders[folderNum]+"/"+photos[photoNum]);
image(photo, 75,25,width-150,width-150);
fill(201,47,331);
textAlign(LEFT);
text("TAG THIS PHOTO:", 75,605);
textSize(12);
text("(not functional", 75,618);
text("in this prototype)", 75,630);
fill(210,227,180);
int width1 = 260;
int width2 = 386;
int width3 = 470;
text("LESBIAN", width1,605);
text("GAY", width1,630);
text("BISEXUAL", width1,655);
text("TRANSGENDER", width1,680);
text("STRAIGHT", width1,705);
text("HOMOPHOBIC", width1, 730);
text("TRANSPHOBIC", width1,755);
text("PERSON", width2, 605);
text("BODY", width2, 630);
text("PEOPLE", width2, 655);
text("PLACE", width2, 680);
text("OBJECT", width2, 705);
text("ANIMAL", width2, 730);
text("TEXT", width2, 755);
text("HAPPY", width3,605);
text("EXCITED", width3,630);
text("SEXY", width3, 655);
text("CONTENT", width3,680);
text("SAD", width3,705);
text("ANGRY", width3,730);
text("AFRAID", width3,755);
strokeWeight(5);
stroke(210,227,180);
line(600,720, 620,735);
line(600,750, 620,735);
noLoop();
}
 
void drawSavedColorData() {
background(210,227,180);
drawTitle();
drawBackButton();
int y=25;
for (int i=0; i<folders.length; i++) {
float x=0;
for (int n=0; n<colors.length; n++) {
fill(colors[n][0],colors[n][1],colors[n][2]);
rect(x,y,width*savedData[i][n],height);
x+=width*savedData[i][n];
}
fill(201,47,331);
textSize(14);
textAlign(RIGHT);
text(labels[i], width*.95, y+40);
y+=150;
}
}
 
void randomPicColors() {
background(210,227,180);
drawTitle();
drawBackButton();
fill(0,0,0);
noStroke();
rect(0,25,width,750);
int folderNum = int(random(5));
File innerDir = new File("/Users/oliverhaimson/Dropbox/Processing/project4/data/"+folders[folderNum]);
String[] photos = innerDir.list();
int photoNum = int(random(photos.length));
PImage photo = loadImage(folders[folderNum]+"/"+photos[photoNum]);
findPixelColors(photo, folderNum);
fill(201,47,331);
textAlign(LEFT);
textSize(14);
text(labels[folderNum], 10, 655);
String name = photos[photoNum].substring(0, photos[photoNum].length()-4);
text(name, 107,655);
image(photo, 500,575,200,200);
fill(210,227,180);
noStroke();
if (slideshow) {
text("SLIDESHOW MODE ON", 10,765);
}
else {
text("CLICK FOR SLIDESHOW MODE", 10,765);
strokeWeight(5);
stroke(210,227,180);
line(650,316, 670,331);
line(650,346, 670,331);
noLoop();
}
}
 
void randomPic() {
background(210,227,180);
drawTitle();
drawBackButton();
int folderNum = int(random(5));
File innerDir = new File("/Users/oliverhaimson/Dropbox/Processing/project4/data/"+folders[folderNum]);
String[] photos = innerDir.list();
int photoNum = int(random(photos.length));
PImage photo = loadImage(folders[folderNum]+"/"+photos[photoNum]);
image(photo, 0,25,width,width);
fill(0,0,0);
rect(0,725,width,50);
fill(201,47,331);
textAlign(LEFT);
textSize(14);
text(labels[folderNum], 10, 742);
String name = photos[photoNum].substring(0, photos[photoNum].length()-4);
text(name, 280,742);
fill(210,227,180);
if (slideshow) {
text("SLIDESHOW MODE ON", 10,765);
}
else {
text("CLICK FOR SLIDESHOW MODE", 10,765);
strokeWeight(5);
stroke(210,227,180);
line(660,735, 680,750);
line(660,765, 680,750);
noLoop();
}
}
 
void drawPhotos() {
background(210,227,180);
drawTitle();
drawBackButton();
float x=0;
float y=25;
for (int i=0; i<folders.length; i++) {
File innerDir = new File("/Users/oliverhaimson/Dropbox/Processing/project4/data/"+folders[i]);
String[] photos = innerDir.list();
fill(0,0,0);
rect(0,y,width,25);
fill(201,47,331);
textAlign(LEFT);
textSize(14);
text(labels[i], 10, y+20);
y+=25;
x=0;
for (int n=photos.length-1; n>(photos.length-141); n--) {
PImage photo = loadImage(folders[i]+"/"+photos[n]);
image(photo,x,y,25,25);
if (x<675) {
x+=25;
}
else {
x=0;
y+=25;
}
}
}
noLoop();
}
 
void drawBackButton() {
noStroke();
fill(201,47,331);
triangle(13,6,13,19,5,12.5);
rect(13,6,20,13);
}
 
void drawTitle() {
textFont(font);
textSize(18);
textAlign(CENTER);
fill(201,47,331);
text("THE DIFFERENT RAINBOWS OF THE INSTAGRAM LGBT RAINBOW",
width*.5, 19);
}
 
void drawStartScreen() {
// find random pic for button 4
if (button4Switch) {
int folderNum = int(random(5));
File innerDir = new File("/Users/oliverhaimson/Dropbox/Processing/project4/data/"+folders[folderNum]);
String[] photos = innerDir.list();
int photoNum = int(random(photos.length));
button4 = loadImage(folders[folderNum]+"/"+photos[photoNum]);
button4Switch = false;
}
// find random pic for button 5
if (button5Switch) {
int picNumber = int(random(button5Pics.length));
button5 = loadImage(button5Pics[picNumber]);
button5Switch = false;
}
// switch button 4 and 5 pic every 200 framecounts
if (frameCount%200 == 0) {
button4Switch = true;
}
if (frameCount%200 == 100) {
button5Switch = true;
}
//
background(210,227,180);
drawTitle();
fill(29,30,335);
noStroke();
rect(0,25,width,height-50);
image(insta, 0, height-284);
fill(26,94,47);
roundRect(50,70,166.67,166.67);
image(button1, 61,81,146.67,146.67);
roundRect(266.67,70,166.67,166.67);
image(button2, 277.67,81,146.67,146.67);
roundRect(483.34,70,166.67,166.67);
image(button3, 494.34,81,146,146.67);
roundRect(50,275,166.67,166.67);
image(button4, 61,286,146.67,146.67);
roundRect(266.67,275,166.67,166.67);
image(button5, 277.67,286,146.67,146.67);
roundRect(483.34,275,166.67,166.67);
image(button6, 494,286,146,146.67);
// change button color and display text if it's hovered over
// button 1
if (mouseX>50 && mouseX<216.67 && mouseY>70 && mouseY<236.67) {
fill(26,200,200);
roundRect(50,70,166.67,166.67);
image(button1, 61,81,146.67,146.67);
fill(0,0,0,250);
rect(61,175,146,52);
fill(210,300,300);
textSize(10);
text("DISPLAY SAVED COLOR", 133.33, 190);
text("DATA FROM FULL", 133.33, 205);
text("SAMPLE OF PICTURES", 133.33, 220);
// button 2
}
else if (mouseX>266.67 && mouseX<433.34 &&
mouseY>70 && mouseY<236.67) {
fill(26,200,200);
roundRect(266.67,70,166.67,166.67);
image(button2, 277.67,81,146.67,146.67);
fill(0,0,0,250);
rect(277,175,146,52);
fill(210,300,300);
textSize(10);
text("DISPLAY COLOR DATA FROM", 349.5, 190);
text("50 MOST RECENT PHOTOS", 349.5, 205);
text("IN EACH CATEGORY", 349.5, 220);
}
// button 3
else if (mouseX>483 && mouseX<639.67 && mouseY>70 && mouseY<236.67) {
fill(26,200,200);
roundRect(483.34,70,166.67,166.67);
image(button3, 494.34,81,146,146.67);
fill(0,0,0,250);
rect(494,175,146,52);
fill(210,300,300);
textSize(10);
text("DISPLAY", 566, 190);
text("140 MOST RECENT PHOTOS", 566, 205);
text("IN EACH CATEGORY", 566, 220);
}
// button 4
else if (mouseX>50 && mouseX<216.67 && mouseY>275 && mouseY<441.67) {
fill(26,200,200);
roundRect(50,275,166.67,166.67);
image(button4, 61,286,146.67,146.67);
fill(0,0,0,250);
rect(61,380,146,52);
fill(210,300,300);
textSize(10);
text("DISPLAY RANDOM", 133.33, 395);
text("PICTURES FROM THE", 133.33, 410);
text("DATA COLLECTION", 133.33, 425);
}
// button 5
else if (mouseX>266.67 && mouseX<433.34 &&
mouseY>275 && mouseY<441.67) {
fill(26,200,200);
roundRect(266.67,275,166.67,166.67);
image(button5, 277.67,286,146.67,146.67);
fill(0,0,0,250);
rect(277,380,147,52);
fill(210,300,300);
textSize(10);
text("DISPLAY RANDOM PICTURES", 350, 395);
text("WITH COLOR MAPPING", 350, 410);
text("ALGORITHM APPLIED", 350, 425);
}
// button 6
else if (mouseX>483 && mouseX<639.67 && mouseY>275 && mouseY<441.67) {
fill(26,200,200);
roundRect(483.34,275,166.67,166.67);
image(button6, 494,286,146,146.67);
fill(0,0,0,250);
rect(494,380,146,52);
fill(210,300,300);
textSize(10);
text("TAG", 566, 402.5);
text("PICTURES", 566, 417.5);
}
if (isLoading) {
image(loading, width/2.0-loading.width/2.0, 106);
}
}
 
void loadPhotos() {
background(210,227,180);
drawTitle();
drawBackButton();
// citation: help with reading in files from a folder came from
// Processing Forum, a user named "clankill3r" at
// http://processing.org/discourse/beta/num_1253083238.html
File dir = new File("/Users/oliverhaimson/Dropbox/Processing/project4/data");
folders = subset(dir.list(), 1,5);
int y=25;
textSize(14);
textAlign(RIGHT);
// i<folders.length
for (int i=0; i<folders.length; i++) {
File innerDir = new File("/Users/oliverhaimson/Dropbox/Processing/project4/data/"+folders[i]);
String[] photos = innerDir.list();
getColors(photos, folders[i], i);
drawColors(photos.length, i, y);
fill(201,47,331);
text(labels[i], width*.95, y+40);
y+=150;
}
noLoop();
}
 
void drawColors(int len, int fold, int y) {
noStroke();
// find total number of pixels in the folder
float totalPixels=0;
for (int n=0; n<colors.length; n++) {
totalPixels+=colorDistr[fold][n];
}
// calculate percentage of each color and draw rectangles
float x=0;
for (int i=0; i<colors.length; i++) {
percents[fold][i] = colorDistr[fold][i]/totalPixels;
fill(colors[i][0],colors[i][1],colors[i][2]);
rect(x,y,width*percents[fold][i],height);
x+=width*percents[fold][i];
}
}
 
void getColors(String [] photos, String folder, int fold) {
int amount;
if (loadAllPhotos) {
amount = photos.length;
}
else {
// load only latest 50 photos
amount = 50;
}
for (int i=photos.length-1; i>photos.length-amount; i--) {
PImage photo = loadImage(folder+"/"+photos[i]);
findPixelColors(photo, fold);
println("Photo "+i+" of "+(photos.length-1)+" in "+folder+
" done!");
}
}
 
void findPixelColors(PImage photo, int fold) {
int i=0;
for (int x=0; x<photo.width; x++) {
for (int y=0; y<photo.height; y++) {
float h = hue(photo.pixels[i]);
float s = saturation(photo.pixels[i]);
float b = brightness(photo.pixels[i]);
// determine if the pixel is black, white, or grey
float closeHue, closeSat, closeBright;
if (b <= 120) { // black
closeHue = 0;
closeSat = 0;
closeBright = 0;
colorDistr[fold][13]+=1;
}
else if (s < 100 && b > 300) { // white
closeHue = 0;
closeSat = 0;
closeBright = 360;
colorDistr[fold][11]+=1;
}
else if (s < 100 && b > 70 && b <= 300) { // grey
closeHue = 0;
closeSat = 0;
closeBright = 180;
colorDistr[fold][12]+=1;
}
// if the pixel is not black, white, or grey, find the pixel's
// closest hue
else {
closeHue = closestHue(h);
// if the hue is <=40, determine if the pixel is brown or
// white people color
if ((h <= 40 | h >= 345) && b < 260) { // brown
closeHue = 40;
closeSat = 360;
closeBright = 130;
colorDistr[fold][10]+=1;
}
else if (h <= 40 && s <= 300 && b >= 190) {
// white people color
closeHue = 20;
closeSat = 104;
closeBright = 316;
colorDistr[fold][9]+=1;
}
else {
// change second red to first red
if (closeHue == 345) {
closeHue = 10;
}
closeBright = 360;
closeSat = 360;
// add to corresponding colorDistr vector
for (int n=0; n<hues.length; n++) {
if (closeHue == hues[n]) {
colorDistr[fold][n]+=1;
}
}
}
}
i = photo.width*y + x;
if (phase==5) {
stroke(closeHue, closeSat, closeBright);
point(x,y+28);
}
}
}
}
float closestHue(float h) {
int currentColor = 0;
float distance = abs(h-hues[0]);
for (int i=1; i<hues.length; i++) {
float d = abs(h-hues[i]);
if (d < distance) {
distance = d;
currentColor = i;
}
}
return hues[currentColor];
}
 
void roundRect(float x, float y, float w, float h) {
rect(x+w*.09,y,w*.82,h);
rect(x,y+h*.09,w,h*.82);
arc(x+w*.1,y+h*.1, w*.2,h*.2, PI,PI+HALF_PI);
arc(x+w*.9,y+h*.1, w*.2,h*.2, PI+HALF_PI,TWO_PI);
arc(x+w*.1,y+h*.9, w*.2,h*.2, HALF_PI,PI);
arc(x+w*.9,y+h*.9, w*.2,h*.2, 0,HALF_PI);
}
 
void mousePressed() {
if (phase==100) {
if (mouseX>50 && mouseX<216.67 && mouseY>70 && mouseY<236.67) {
phase=1;
isLoading=false;
}
else if (mouseX>266.67 && mouseX<433.34 &&
mouseY>70 && mouseY<236.67) {
isLoading=true;
drawStartScreen();
phase=2;
isLoading=false;
}
else if (mouseX>483.34 && mouseX<650 &&
mouseY>70 && mouseY<236.67) {
isLoading=true;
drawStartScreen();
phase=3;
isLoading=false;
}
else if (mouseX>50 && mouseX<216.67 &&
mouseY>275 && mouseY<441.67) {
phase=4;
}
else if (mouseX>266.67 && mouseX<433.34 &&
mouseY>275 && mouseY<441.67) {
isLoading=true;
drawStartScreen();
phase=5;
isLoading=false;
}
else if (mouseX>483.34 && mouseX<650 &&
mouseY>275 && mouseY<441.67) {
phase=6;
}
}
else if (phase!=100) {
if (mouseX>5 && mouseX<33 && mouseY>6 && mouseY<19) {
loop();
phase=100;
slideshow=false;
}
}
if (phase==4 || phase==5) {
if (mouseX<220 && mouseY>750) {
slideshow=!slideshow;
}
loop();
}
if (phase==6) {
if (mouseX>600 && mouseX<625 && mouseY>720 && mouseY<750) {
loop();
}
}
}
 
void keyPressed() {
if (phase==4 || phase==5) {
loop();
}
if (key == 'P') {
saveFrame("screenshot.png");
}
// if (key == 'S') {
// println("Saving....");
// saveData();
// }
}

Stephanie – LED Shirt

My final project was to sew a shirt that had RGB LEDs on the sleeves whose flashing modulation could be controlled by three buttons in the palms.

Since the final presentations on Wednesday I’ve finally mastered the pin mapping, and now each button corresponds to a different mode of flashing on your arm.

When the project was announced I knew I wanted to make something wearable with RGB LEDs. I started out thinking about making an armored gauntlet that glowed, but the idea soon grew into an entire shirt covered with LEDs. I bought a Lilypad Arduino from Sparkfun to control the LEDs, but realized too late that it did not have enough I/O pins to control all of them. Looking back I could have tried out individually addressable LEDs, but I think the ones I used look nicer.

Since my LEDs were not individually addressable this meant I needed a ton of I/O pins to control them. I had thirty LEDs on my strip and I cut it into ten short strips of three lights each. Five segments would go on each arm, and each segment needed four wires to control the lights. This meant I needed about 40 I/O pins just to power the LEDs, and not including the buttons I’d use to control them. My Arduino and Lilypad didn’t have nearly enough I/O pins, but my dad had a ChipKit Max 32 lying around from a previous project of his that he lent me. (He’s an electrical engineer at NASA so he often gets stuff like this for fun.) The ChipKit is a pretty amazing board. It has a whopping 83 I/O pins and built in Ethernet capabilities. Adafruit and Sparkfun don’t have them, but they can be ordered here:
http://www.digilentinc.com/Products/Catalog.cfm?NavPath=2,892&Cat=18
The data sheet that I referenced for the pin mapping is here:

It requires a different programming environment than Arduino, but it works in exactly the same way. Much like how Arduino is similar to Processing.

Each LED segment is soldered on to a piece of ribbon cable, which was easily attached to a 2×17 pin connector that could easily be plugged in and taken out from the ChipKit. Five of the ribbon cable wires needed to be dedicated to the button panels on the palms of the sleeves; 1 power, 1 ground, and 3 signal. The actual button panels were salvaged/cannibalized from a dead Sony VCR and came already-soldered with the correct resistors.

Unfortunately, Fritzing has no support for the ChipKit and doesn’t seem to know what ribbon cable is either. But here is a general idea of what the wiring for one arm would look like:

And an actual picture of the connectors to the ChipKit. The (barely visible) diodes are for providing the correct voltage drop when the LEDs are plugged in but unlit.

Sewing the shirt out of spandex only took me a few minutes, but attaching the LEDs to the sleeves took way longer. The stiff wires would stretch the fabric in ways that made it difficult to sew, and the adhesive on the back on the LED strips was no help whatsoever. In order to keep the pins on the bottom of the ChipKit from poking me in the back, and to make the garment (theoretically) washable I attached velcro to the bottom of the control board and stuck it to a panel of craft foam I sewed on to the back of the shirt.

Altogether, I’m really happy with how this project turned out. I learned a lot about pull-down resistors, pin mapping, and the wonders of ribbon cable. I also figured out how to sew a shirt out of spandex and learned a new soldering technique from my dad. The design of the electronics was well executed but I wish there was a better way of attaching the LEDs to the shirt because they stick out at awkward angles sometimes. I’m also really pleased with the way the light travels up and down the sleeves when the buttons are pressed. It would have been cool to use PWM to fade them, but there are only five PWM pins on the board. Not to mention that it would involve heavy alteration of my existing design to incorporate them.

I’ve been talking with a friend of mine about possibly getting a pair of these shirts exhibited in a rave runway fashion show he is planning. He’s very enthusiastic about featuring them and it’s an exciting idea, but if I were to do that I would have to think about streamlining the integration of the electronics into the fabric and deal with the issue of battery life. Currently this piece eats a 9V battery every 10 minutes or so when it’s not plugged in to the wall.

In the future I’d love to make more of these with higher durability and more light control options for performances and dancing.

Code

int ledString1L[] = {  // string 1 green/red/blue J3/J14
  44, 84, 83};
 
int ledString2L[] = {  // string 2 green/red/blue J3/J14
  13, 82, 12};
 
int ledString3L[] = {  // string 3 green/red/blue J3/J14
  11, 80, 10};
 
int ledString4L[] = {  // string 4 green/red/blue J3/J14
  9, 78, 8};
 
int ledString5L[] = {  // string 5 green/red/blue J3/J14
  7, 76, 6};
 
int ledString1R[] = {  // string 1 green/red/blue J8/J9
  23, 22, 25};
 
int ledString2R[] = {  // string 2 green/red/blue J8/J9
  30, 28, 29};
 
int ledString3R[] = {  // string 3 green/red/blue J8/J9
  31, 32, 33};
 
int ledString4R[] = {  // string 4 green/red/blue J8/J9
  35, 36, 37};
 
int ledString5R[] = {  // string 5 green/red/blue J8/J9
  39, 40, 41};
 
const int button1RPin = 53;
int button1RState = 0;
 
const int button2RPin = 52;
int button2RState = 0;
 
const int button3RPin = 51;
int button3RState = 0;
 
const int button1LPin = 70;
int button1LState = 0;
 
const int button2LPin = 0;
int button2LState = 0;
 
const int button3LPin = 1;
int button3LState = 0;
 
void setup() {                
  // initialize the digital pin as an output.
  int i;
  for (int i = 0; i < 3; i++) {
    pinMode(ledString1L[i], OUTPUT);  
    digitalWrite(ledString1L[i], HIGH);    // set the LED off
  }
  for (int i = 0; i < 3; i++) {
    pinMode(ledString2L[i], OUTPUT);  
    digitalWrite(ledString1L[i], HIGH);    // set the LED off
  }
  for (int i = 0; i < 3; i++) {
    pinMode(ledString3L[i], OUTPUT);  
    digitalWrite(ledString1L[i], HIGH);    // set the LED off
  }
  for (int i = 0; i < 3; i++) {
    pinMode(ledString4L[i], OUTPUT);  
    digitalWrite(ledString1L[i], HIGH);    // set the LED off
  }
  for (int i = 0; i < 3; i++) {
    pinMode(ledString5L[i], OUTPUT);  
    digitalWrite(ledString1L[i], HIGH);    // set the LED off
  }
  for (int i = 0; i < 3; i++) {
    pinMode(ledString1R[i], OUTPUT);  
    digitalWrite(ledString1L[i], HIGH);    // set the LED off
  }
  for (int i = 0; i < 3; i++) {
    pinMode(ledString2R[i], OUTPUT);  
    digitalWrite(ledString1L[i], HIGH);    // set the LED off
  }
  for (int i = 0; i < 3; i++) {
    pinMode(ledString3R[i], OUTPUT);  
    digitalWrite(ledString1L[i], HIGH);    // set the LED off
  }
  for (int i = 0; i < 3; i++) {
    pinMode(ledString4R[i], OUTPUT);  
    digitalWrite(ledString1L[i], HIGH);    // set the LED off
  }
  for (int i = 0; i < 3; i++) {
    pinMode(ledString5R[i], OUTPUT);  
    digitalWrite(ledString1L[i], HIGH);    // set the LED off
  }
  pinMode (button1RPin, INPUT);
  pinMode (button2RPin, INPUT);
  pinMode (button3RPin, INPUT);
 
  pinMode (button1LPin, INPUT);
  pinMode (button2LPin, INPUT);
  pinMode (button3LPin, INPUT);
 
}
void loop() {
  button1RState = digitalRead(button1RPin);
  if (button1RState == HIGH) {  
    int del=50;
    for (int i = 0; i++) {
      digitalWrite(ledString5R[i], LOW);   // set the LED on
      delay(del);               // wait
      digitalWrite(ledString5R[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString4R[i], LOW);   // set the LED on
      delay(del);               // wait
      digitalWrite(ledString4R[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString3R[i], LOW);   // set the LED on
      delay(del);               // wait
      digitalWrite(ledString3R[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString2R[i], LOW);   // set the LED on
      delay(del);               // wait
      digitalWrite(ledString2R[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString1R[i], LOW);   // set the LED on
      delay(del);               // wait
      digitalWrite(ledString1R[i], HIGH);    // set the LED off
    }
  }
  else {
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString1R[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString2R[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString3R[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3  ; i++) {
      digitalWrite(ledString4R[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString5R[i], HIGH);    // set the LED off
    }
  }
button2RState = digitalRead(button2RPin);
  if (button2RState == HIGH) {  
    int del=50;
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString1R[i], LOW);   // set the LED on
      delay(del);               // wait
      digitalWrite(ledString1R[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString2R[i], LOW);   // set the LED on
      delay(del);               // wait
      digitalWrite(ledString2R[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString3R[i], LOW);   // set the LED on
      delay(del);               // wait
      digitalWrite(ledString3R[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString4R[i], LOW);   // set the LED on
      delay(del);               // wait
      digitalWrite(ledString4R[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString5R[i], LOW);   // set the LED on
      delay(del);               // wait
      digitalWrite(ledString5R[i], HIGH);    // set the LED off
    }
  }
  else {
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString1R[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString2R[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString3R[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3  ; i++) {
      digitalWrite(ledString4R[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString5R[i], HIGH);    // set the LED off
    }
  }
 button3RState = digitalRead(button3RPin);
  if (button3RState == HIGH) {  
    int del=10;
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString1R[i], LOW);    // set the LED on
      delay(del); 
    digitalWrite(ledString1R[i], HIGH);
    }
  }
  else{
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString1R[i], HIGH);    // set the LED off
    }
  }
button1LState = digitalRead(button1LPin);
  if (button1LState == HIGH) {  
    int del=50;
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString1L[i], LOW);   // set the LED on
      delay(del);               // wait
      digitalWrite(ledString1L[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString2L[i], LOW);   // set the LED on
      delay(del);               // wait
      digitalWrite(ledString2L[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString3L[i], LOW);   // set the LED on
      delay(del);               // wait
      digitalWrite(ledString3L[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString4L[i], LOW);   // set the LED on
      delay(del);               // wait
      digitalWrite(ledString4L[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString5L[i], LOW);   // set the LED on
      delay(del);               // wait
      digitalWrite(ledString5L[i], HIGH);    // set the LED off
    }
  }
  else {
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString1L[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString2L[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString3L[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString4L[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString5L[i], HIGH);    // set the LED off
    }
  }
 
   button2LState = digitalRead(button2LPin);
  if (button2LState == HIGH) {  
    int del=50;
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString5L[i], LOW);   // set the LED on
      delay(del);               // wait
      digitalWrite(ledString5L[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString4L[i], LOW);   // set the LED on
      delay(del);               // wait
      digitalWrite(ledString4L[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString3L[i], LOW);   // set the LED on
      delay(del);               // wait
      digitalWrite(ledString3L[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString2L[i], LOW);   // set the LED on
      delay(del);               // wait
      digitalWrite(ledString2L[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString1L[i], LOW);   // set the LED on
      delay(del);               // wait
      digitalWrite(ledString1L[i], HIGH);    // set the LED off
    }
  }
  else {
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString1L[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString2L[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString3L[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString4L[i], HIGH);    // set the LED off
    }
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString5L[i], HIGH);    // set the LED off
    }
  }
 
  button3LState = digitalRead(button3LPin);
  if (button3LState == HIGH) {  
    int del=30;
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString1L[i], LOW);    // set the LED on
      delay(del); 
    digitalWrite(ledString1L[i], HIGH);
    }
  }
  else{
    for (int i = 0; i<3; i++) {
      digitalWrite(ledString1L[i], HIGH);    // set the LED off
    }
  }
}

A Drink Bot – Kyna McIntosh

EDIT: Currently running at https://twitter.com/SonofaDrinkBot

So I created a bot that detects whenever someone tweets ‘i need a drink,’ and, using their name and message, concocts a mixed drink, and sends an image of it to the user.

I was suspended within the first 3 minutes for spam (I was tweeting once every 15 seconds or so).

Here’s the page now : https://twitter.com/A_Drink_Bot

And what it looked like before I got banned :

The first ban was just a warning ban, and I randomized my tweets a bit and only posted once every two or three minutes after I ‘unsuspended’ myself.

Because the drinks were somewhat randomized, some of them sounded pretty good and others sounded like you would go blind from drinking them…
Here’s the flickr gallery containing all of the drinks my bot made during its short, short life : http://www.flickr.com/photos/90787080@N06/sets/72157632174450103/

I was permanently suspended within a half hour.

CODE!

import twitter4j.conf.*;
import twitter4j.internal.async.*;
import twitter4j.internal.org.json.*;
import twitter4j.internal.logging.*;
import twitter4j.auth.*;
import twitter4j.api.*;
import twitter4j.util.*;
import twitter4j.internal.http.*;
import twitter4j.*;
import twitter4j.media.*;
import java.io.File.*;
 
static String OAuthConsumerKey    = "*";
static String OAuthConsumerSecret = "*";
static String AccessToken         = "*";
static String AccessTokenSecret   = "*";
 
Twitter myTwitter;
 
String  myQueryPhrase = "i need a drink";  
long    previousIdOfTweetContainingQuery = 0;
 
class Ingredient {
  String name;
  String img;
 
  Ingredient(String nameOf, String imgPath) {
    name = nameOf;
    img = imgPath;
  }
}
 
class Drink {
  String name;
  String alcohol;
  String mixer;
  String garnish;
  String alcohol2;
 
  Drink(String n, String a, String m, String g, String a2) {
    name = n;
    alcohol = a;
    mixer = m;
    garnish = g;
    alcohol2 = a2;
  }
}
 
ArrayList alcohols;
ArrayList mixers;
ArrayList garnish;
 
void setup() {
 
  size(525, 350);
  background(255);
  frameRate(10);
 
  imageMode(CENTER);
 
  alcohols = new ArrayList();
  mixers = new ArrayList();
  garnish = new ArrayList();
 
  //gotta make list of alcohol and imgs
  String tempAlcohols[] = loadStrings("alcohols/alcohols.txt");
  for (int i=0; i < tempAlcohols.length; i++) {
    String holdA[] = split(tempAlcohols[i], &#039;_&#039;);
    println(holdA[0]);
    println(holdA[1]);
    alcohols.add(new Ingredient(holdA[0], holdA[1]));
  }
 
  //gotta make list of mixers and imgs
  String tempMixers[] = loadStrings("mixers/mixers.txt");
  for (int j=0; j < tempMixers.length; j++) {
    String holdM[] = split(tempMixers[j], &#039;_&#039;);
    mixers.add(new Ingredient(holdM[0], holdM[1]));
  }
 
  //gotta make list of garnish and imgs
  String tempGarnish[] = loadStrings("garnish/garnish.txt");
  for (int k=0; k = a) {
    two = true;
    int newRand2 = (int)map(rand2, 0, 10*(user.length()), 0, alcohols.size());
    Ingredient alc2 = alcohols.get(newRand2);
    PImage alc2img = loadImage("alcohols/" + alc2.img);
    alc2img.resize(250, 250);
    image(alc2img, 150, 200);
    text(alc2.name, 275, 200);
  }
}
void makeDrink(String user, String message) {
  fill(0);
  textSize(18);
  boolean two = false; 
 
  //generate alcohol
  int a = (int)(user.charAt(0));
  int newA = (int)map(a, 0, 127, 0, alcohols.size());
  Ingredient alc = alcohols.get(newA);
  PImage alcimg = loadImage("alcohols/" + alc.img);
  alcimg.resize(250, 250);
  image(alcimg, 150, 200);
  text(alc.name, 275, 150);  
 
  //add extra alcohol?
  int rand2 = (int)(random(0, 10*(user.length())));
  if (rand2 >= a) {
    two = true;
    int newRand2 = (int)map(rand2, 0, 10*(user.length()), 0, alcohols.size());
    Ingredient alc2 = alcohols.get(newRand2);
    PImage alc2img = loadImage("alcohols/" + alc2.img);
    alc2img.resize(250, 250);
    image(alc2img, 150, 200);
    text(alc2.name, 275, 200);
  }
 
  //generate mixer
  int rand1 = (int)(random(0, (message.length())));
  int b = (int)(message.charAt(rand1));
  int newB = (int)map(b, 0, 127, 0, mixers.size());
  Ingredient mix = mixers.get(newB);
  PImage miximg = loadImage("mixers/" + mix.img);
  miximg.resize(250, 250);
  image(miximg, 150, 200);
  if (two == true) text(mix.name, 275, 250);
  else text(mix.name, 275, 200);
 
  //add garnish?
  int rand3 = (int)(random(0, rand2));
  int newRand3 = (int)map(rand3, 0, rand2, 0, garnish.size());
  if (newRand3 <= a) {
    Ingredient gar = garnish.get(newRand3);
    PImage garimg = loadImage("garnish/" + gar.img);
    garimg.resize(250, 250);
    image(garimg, 150, 200);
    if (two == true) text(gar.name, 275, 300);
    else text(gar.name, 275, 250);
  }
 
  PImage glass = loadImage("glass.png");
  glass.resize(250, 250);
  image(glass, 150, 200);
 
  textSize(36);
 
  text("The "+ user, 50, 50, 450, 150); 
  //put a name on dat shit
 
  //save dat shit
  save("/processing-2.0b3/"+user+".png");
}
void draw() {
  background(255);
 
  ConfigurationBuilder cb = new ConfigurationBuilder();
  cb.setOAuthConsumerKey(OAuthConsumerKey);
  cb.setOAuthConsumerSecret(OAuthConsumerSecret);
  cb.setOAuthAccessToken(AccessToken);
  cb.setOAuthAccessTokenSecret(AccessTokenSecret);
 
  Twitter myTwitter = new TwitterFactory(cb.build()).getInstance();
 
  try {
    println ("Searching.... Current time = " + hour() + ":" + minute() + ":" + second()); 
    Query query = new Query(myQueryPhrase);
    //maybe because i changed the way it was arranged??
    QueryResult result = myTwitter.search(query);
 
    ArrayList tweetsContainingQuery = (ArrayList) result.getTweets();
    if (tweetsContainingQuery.size() > 0) {
      Status mostRecentTweetContainingQuery = (Status) tweetsContainingQuery.get(0);
      long mostRecentTweetContainingQueryId = mostRecentTweetContainingQuery.getId();
 
      if (previousIdOfTweetContainingQuery == 0) {
        previousIdOfTweetContainingQuery = mostRecentTweetContainingQueryId;
      }
      if (mostRecentTweetContainingQueryId != previousIdOfTweetContainingQuery) {
        // yay! someone has just tweeted our favorite word!
        previousIdOfTweetContainingQuery = mostRecentTweetContainingQueryId;
 
        // print out the new tweet, for fun. 
        User used = mostRecentTweetContainingQuery.getUser();
        String user = used.getName();
        String username = used.getScreenName();
        String msg = mostRecentTweetContainingQuery.getText();
        Date d = mostRecentTweetContainingQuery.getCreatedAt();
 
        makeDrink(username, msg);
 
        //new error
        File src = new File(username+".png");
 
        File real = new File(src.getAbsolutePath());
 
        String stat = ("@"+username+" I heard you needed a drink, so I made you one. ");
 
        StatusUpdate status = new StatusUpdate(stat);
        status.setMedia(real);
 
        status.setInReplyToStatusId(mostRecentTweetContainingQueryId);
        myTwitter.updateStatus(status);
 
        println("Tweet by " + user + " at " + d + ": " + msg);
      }
    }
  }
 
  catch (TwitterException te) {
    println("Error connecting to Twitter: " + te);
  };
 
  delay (12000); // REALLY IMPORTANT, PEOPLE. You're limited to 350 requests per hour, or about once per 11 seconds.
}

The Turkey’s Alive! – Sarah Anderson

For this project I decided to continue the holiday theme and do a piece about thanksgiving, which I am greatly looking forward to. For this piece I slaved all day to make this slightly overcooked turkey in a real metal pan, but when I press the giant red turkey timer button, IT COMES ALIVE!!! A servo in each leg kicks them back and forth for five seconds at random positions.

There are currently no pictures or videos since I still have not had a chance to fix the soldering and mechanical issues, but they will be up before break.

 

CODE

 

//Sarah Anderson, seanders
//EMS 2
 
#includeServo servo1, servo2;  
const int redButton = 11;
int prevCTime;
int period=5000;
 
void setup()
{
  pinMode(redButton, INPUT);
  servo1.attach(9);
  servo2.attach(10);
  prevCTime=0;
}
 
void loop()
{
  int redButtonState;
  redButtonState = digitalRead(redButton);
  int curTime= millis();
  int elapsed = curTime-prevCTime;
 
  if (redButtonState==LOW){ 
    prevCTime=curTime;

while (elapsed<period){
curTime= millis();
servo1.write(random(0,180));
servo2.write(random(0,180));
redButtonState = digitalRead(redButton);
delay(500);
elapsed = curTime-prevCTime;
}

}
}

(it would not let me put all the code together for some reason….)

Circuitry

 

Fancy Mr. Rex

 
In a time long long ago there was a dinosaur who was quite unlike the rest.
For he wore something peculiar on his chest.
His name was Fancy Mr. Rex
He didn’t have big muscles to flex
Rex had pondered for ages what to do,
It was Tyra he did pursue
He couldn’t figure out how to impress
So he decided to class up his dress
It took him fortnights to decide,
It was the fanciest of bows he tied.

The above poem gives more insight into the story behind Fancy Mr. Rex and why he wears a bow tie. The following processing sketch is the origin of Fancy Mr. Rex.
Processing Sketch: http://www.openprocessing.org/sketch/68556

If I were to expand this piece/improve it, I would make the background move one a track so as to appear that it is scrolling. I would also attach Rex to some main support that would hold up his wait so that his weight wasn’t rested on the servo motors. This would also for smoother more realistic motion. Also some of the directly attached servo motors would be better done with pulley systems.

Here is the Fritzing Diagram:

Here is the code for ze fancyest of dinos:

#include    // servo library
Servo servo1;  // servo control object
Servo servo2;  // servo control object
Servo servo3;  // servo control object
Servo servo4;  // servo control object
//Servo servo5;  // servo control object
 
const int buttonPin = 2;
boolean onOffSwitch = false;
 
//-----WALK SETTINGS-----
int walkState = 1;
int walkStateNum = 5;
int waitTime = 150;
 
void setup()
{
  pinMode(buttonPin, INPUT);
 
  walkState = 1;
 
  servo1.attach(5);  //---jaw
  servo2.attach(6);  //---leg behind
  servo3.attach(9);  //---leg infront
  servo4.attach(10); //---arms
  //servo5.attach(11); //---extra arm
 
  onOffSwitch = true;
  normalMode ();
}
 
void loop()
{
  //-----Check Button State-----
  int  buttonState = digitalRead(buttonPin);
 
  if (buttonState == LOW)
  {
    onOffSwitch = -onOffSwitch;
  }
 
  if (onOffSwitch)
  {
    walkMode();
  }
  else
  {
    normalMode();
  }
}
 
void normalMode ()
{
 
}
 
void walkMode ()
{
  //-------SERVO CODE-------
  if (millis() % waitTime == 0)
  {
    walkState = (walkState + 1) % walkStateNum;
    updateJaw(walkState);
    updateLegBehind(walkState);
    updateLegInFront(walkState);
    updateArms(walkState);
  }
}
 
void updateJaw(int walkS)
{
  int positionSet;
  if (walkS % 3 == 0)
  {
    positionSet = map(random(0, 100), 0, 100, 110, 160);
  }
  else if (walkS % 3 == 1)
  {
    positionSet = map(random(0, 100), 0, 100, 110, 160);
  }
  else
  {
    positionSet = map(random(0, 100), 0, 100, 110, 160);
  }
 
  servo1.write(positionSet);  // Move to next position
}
 
void updateLegBehind(int walkS)
{
  int positionSet;
  if (walkS % 3 == 0)
  {
    positionSet = map(random(0, 100), 0, 100, 110, 160);
  }
  else if (walkS % 3 == 1)
  {
    positionSet = map(random(0, 100), 0, 100, 110, 160);
  }
  else
  {
    positionSet = map(random(0, 100), 0, 100, 110, 160);
  }
 
  servo2.write(positionSet);  // Move to next position
}
 
void updateLegInFront(int walkS)
{
  int positionSet;
  if (walkS % 3 == 0)
  {
    positionSet = map(random(0, 100), 0, 100, 110, 120);
  }
  else if (walkS % 3 == 1)
  {
    positionSet = map(random(0, 100), 0, 100, 60, 80);
  }
  else
  {
    positionSet = map(random(0, 100), 0, 100, 0, 30);
  }
 
  servo3.write(positionSet);  // Move to next position
}
 
void updateArms(int walkS)
{
  int positionSet;
  if (walkS % 3 == 0)
  {
    positionSet = map(random(0, 100), 0, 100, 130, 140);
  }
  else if (walkS % 3 == 1)
  {
    positionSet = map(random(0, 100), 0, 100, 140, 160);
  }
  else
  {
    positionSet = map(random(0, 100), 0, 100, 160, 180);
  }
 
  servo4.write(positionSet);  // Move to next position
}

Andrea Gershuny– Hallouino!

My project is a little derpy bat whose eyes light up and arms move and make noise. Unfortunately, in the process of putting his guts inside his body his left eye got disconnected somehow! What a tragedy. (I am going to go back and fix it.) I also couldn’t get the switch to work properly… I originally had a big red button to control him instead of the switch, but the wires kept breaking off (at least five times…) so I swapped it out for a switch and it didn’t work. But derpy bat 2.0 is on its way!

Also unfortunately, this is mostly a placeholder post for now because I haven’t uploaded the photos yet. But high quality video and photos are coming soon!