All posts by Kathryn Ruhl

Catch One Direction

welcome

For my final project, I went further with the One Direction game I have been working on for the past few weeks! It now has four levels, a start screen, and end screen. The game can also be restarted by pressing ‘r’ and if the user chooses to leave the game before they reach the end, they can press ‘q’ and it will bring them to the quit screen (different from the winning end screen). For music, I made a mashup of a handful of their songs. The user doesn’t have to just listen to one song! I was going to add some sort of sound effect for when the crazy fan catches one of the boys… but as the number of them grew.. I could feel my brain wanted to explode from that number of repetitive sounds.

Also, if you are curious about which songs I used for the background track:
“One Way or Another (Teenage Kicks)”
What Makes You Beautiful
Kiss You
Live While We’re Young
Best Song Ever
Happily (one of my personal favorites)

Level One:
Catch1D_L1
This is the slowest level with only one of each member. I also decided to put the instructions on this page with a transparent background with mildly opaque instructions (made in Photoshop).

Level Two:
Catch1D_L2

Level Three:
Catch1D_L3

Level Four // Bonus Level:
Catch1D_L4

Quit Screen (in case you don’t have the patience to get to the end!):

quit

 

End Screen:
end

 

 

————CODE ————

import ddf.minim.*;
import processing.serial.*;

Minim minim;
AudioPlayer player;
Serial myPort;

PImage welcomePic;
PImage endPic;
PImage logo;
PImage quit;
PImage instructions;

Member [] oneDirection = new Member[5];
Member [] levelTwo = new Member[10];
Member [] levelThree = new Member[25];
Member [] bonusLevel = new Member[50];

float xPos, yPos;
float xSpeed, ySpeed;
PImage harry, liam, louis, niall, zayn; 
PImage [] boy = {harry, liam, louis, niall, zayn };
boolean overBoy;

CrazyFan fan;
PImage crazyFan;
float fanXpos, fanYpos;
float fanXspeed, fanYSpeed;

boolean start, level_One,level_Two, level_Three, bonus_Level, endGame;
boolean quitGame;

void setup(){
  size(800,600); 

  welcomePic = loadImage("welcome.png");
  endPic = loadImage("end.png");
  logo = loadImage("logo.png");
  quit = loadImage("quit.png");
  instructions = loadImage("instructions.png");

  start=false;

  level_One=true;
  level_Two=true;
  level_Three=true;
  bonus_Level=true;

  endGame=false;
  quitGame=false;

  crazyFan = loadImage("crazyFan.png");
  harry = loadImage("Harry_Styles.png");
  liam = loadImage("Liam_Payne.png");
  louis = loadImage("Louis_Tomlinson.png");
  niall = loadImage("Niall_Horan.png");
  zayn = loadImage("Zayn_Malik.png");

  fan = new CrazyFan(crazyFan, fanXpos, fanYpos);
  oneDirection[0] = new Member(harry, xPos, yPos);
  oneDirection[1] = new Member(liam, xPos, yPos);
  oneDirection[2] = new Member(louis, xPos, yPos);
  oneDirection[3] = new Member(niall, xPos, yPos);
  oneDirection[4] = new Member(zayn, xPos, yPos);

 minim = new Minim(this);
 player = minim.loadFile("mashup.mp3");
 player.play();

  //fill levelTwo
  for(int i=0; i<2; i++){
      levelTwo[5*i] = new Member(harry, xPos, yPos);
      levelTwo[5*i+1] = new Member(liam, xPos, yPos);
      levelTwo[5*i+2] = new Member(louis, xPos, yPos);
      levelTwo[5*i+3] = new Member(niall, xPos, yPos);
      levelTwo[5*i+4] = new Member(zayn, xPos, yPos);
    }

   //fill levelThree   
   for(int i=0; i<5; i++){
      levelThree[5*i] = new Member(harry, xPos, yPos);
      levelThree[5*i+1] = new Member(liam, xPos, yPos);
      levelThree[5*i+2] = new Member(louis, xPos, yPos);
      levelThree[5*i+3] = new Member(niall, xPos, yPos);
      levelThree[5*i+4] = new Member(zayn, xPos, yPos);
    }

   //fill bonusLevel  
   for(int i=0; i<10; i++){
      bonusLevel[5*i] = new Member(harry, xPos, yPos);
      bonusLevel[5*i+1] = new Member(liam, xPos, yPos);
      bonusLevel[5*i+2] = new Member(louis, xPos, yPos);
      bonusLevel[5*i+3] = new Member(niall, xPos, yPos);
      bonusLevel[5*i+4] = new Member(zayn, xPos, yPos);
    }

}

void draw(){ 

  if(endGame==false){
     background(255);
      if(start==false){
            image(welcomePic,0,0);
          }
     image(logo,0,0);
  }  

  levelUp();

  if (endGame==true){
    background(255);
    image(endPic,0,0);
    if (quitGame==true){
      image(quit,0,0);
    }
  }

}  

//----------------LEVEL ONE----------------
void levelOneFreeze(){
  for (int i = 0; i < 5; i ++){
     if (dist(oneDirection[i].xPos, oneDirection[i].yPos, fan.fanXpos, fan.fanYpos)<= 75){
       oneDirection[i].overBoy=true;
       oneDirection[i].freezeBoy();
      }//dist
   }
}
void levelOne(){
  for (int i = 0; i < 5; i ++){
      oneDirection[i].positionChange();
      oneDirection[i].levelOneDrawLad();
  }
  fan.positionChange();
  fan.levelOneDrawFan();
}

//----------------LEVEL TWO----------------
void levelTwoFreeze(){
  for (int i = 0; i < 10; i ++){
     if (dist(levelTwo[i].xPos, levelTwo[i].yPos, fan.fanXpos, fan.fanYpos)<= 50){
       levelTwo[i].overBoy=true;
       levelTwo[i].freezeBoyTwo();
      }//dist
   }
}
void levelTwo(){
  for (int i = 0; i < 10; i ++){
      levelTwo[i].positionChangeTwo();
      levelTwo[i].levelTwoDrawLad();
  }
  fan.positionChange();
  fan.levelTwoDrawFan();
}

//----------------LEVEL THREE----------------
void levelThreeFreeze(){
  for (int i = 0; i < 25; i ++){
     if (dist(levelThree[i].xPos, levelThree[i].yPos, fan.fanXpos, fan.fanYpos)<= 40){
       levelThree[i].overBoy=true;
       levelThree[i].freezeBoyThree();
      }//dist
   }
}
void levelThree(){
  for (int i = 0; i < 25; i ++){
      levelThree[i].positionChange();
      levelThree[i].levelThreeDrawLad();
  }
  fan.positionChange();
  fan.levelThreeDrawFan();
}

//----------------BONUS LEVEL----------------
void bonusLevelFreeze(){
  for (int i = 0; i < 50; i ++){
     if (dist(bonusLevel[i].xPos, bonusLevel[i].yPos, fan.fanXpos, fan.fanYpos)<= 40){
       bonusLevel[i].overBoy=true;
       bonusLevel[i].freezeBoyBonus();
      }//dist
   }
}
void bonusLevel(){
  for (int i = 0; i < 50; i ++){
      bonusLevel[i].positionChangeBonus();
      bonusLevel[i].bonusLevelDrawLad();
  }
  fan.positionChange();
  fan.bonusLevelDrawFan();
}

//--------------------------------------------

void levelUp(){
  if(start==true){
    if (level_One){
      levelOne();
      image(instructions,0,0);
      if (oneDirection[0].overBoy==true && oneDirection[1].overBoy==true && oneDirection[2].overBoy==true && oneDirection[3].overBoy==true && oneDirection[4].overBoy==true){
        level_One = false;
      }
    }
    else if(level_Two){
      levelTwo();
      if (levelTwo[0].overBoy==true && levelTwo[1].overBoy==true && levelTwo[2].overBoy==true && levelTwo[3].overBoy==true && levelTwo[4].overBoy==true && levelTwo[5].overBoy==true && levelTwo[6].overBoy==true && levelTwo[7].overBoy==true && levelTwo[8].overBoy==true && levelTwo[9].overBoy==true){
            level_Two = false;
          }
       }
    else if(level_Three){  
       levelThree();
       if (levelThree[0].overBoy==true && levelThree[1].overBoy==true && levelThree[2].overBoy==true && levelThree[3].overBoy==true && levelThree[4].overBoy==true && levelThree[5].overBoy==true && levelThree[6].overBoy==true && levelThree[7].overBoy==true && levelThree[8].overBoy==true && levelThree[9].overBoy==true && levelThree[10].overBoy==true && levelThree[11].overBoy==true && levelThree[12].overBoy==true && levelThree[13].overBoy==true && levelThree[14].overBoy==true && levelThree[15].overBoy==true && levelThree[16].overBoy==true && levelThree[17].overBoy==true && levelThree[18].overBoy==true && levelThree[19].overBoy==true && levelThree[20].overBoy==true && levelThree[21].overBoy==true && levelThree[22].overBoy==true && levelThree[23].overBoy==true && levelThree[24].overBoy==true){
           level_Three = false;
        }
    }
   else if(bonus_Level){
      bonusLevel();
       if (bonusLevel[0].overBoy==true && bonusLevel[1].overBoy==true && bonusLevel[2].overBoy==true && bonusLevel[3].overBoy==true && bonusLevel[4].overBoy==true && bonusLevel[5].overBoy==true && bonusLevel[6].overBoy==true && bonusLevel[7].overBoy==true && bonusLevel[8].overBoy==true && bonusLevel[9].overBoy==true && bonusLevel[10].overBoy==true && bonusLevel[11].overBoy==true && bonusLevel[12].overBoy==true && bonusLevel[13].overBoy==true && bonusLevel[14].overBoy==true && bonusLevel[15].overBoy==true && bonusLevel[16].overBoy==true && bonusLevel[17].overBoy==true && bonusLevel[18].overBoy==true && bonusLevel[19].overBoy==true && bonusLevel[20].overBoy==true && bonusLevel[21].overBoy==true && bonusLevel[22].overBoy==true && bonusLevel[23].overBoy==true && bonusLevel[24].overBoy==true && bonusLevel[25].overBoy==true && bonusLevel[26].overBoy==true && bonusLevel[27].overBoy==true && bonusLevel[28].overBoy==true && bonusLevel[29].overBoy==true && bonusLevel[30].overBoy==true && bonusLevel[31].overBoy==true && bonusLevel[32].overBoy==true && bonusLevel[33].overBoy==true && bonusLevel[34].overBoy==true && bonusLevel[35].overBoy==true && bonusLevel[36].overBoy==true && bonusLevel[37].overBoy==true && bonusLevel[38].overBoy==true && bonusLevel[39].overBoy==true && bonusLevel[40].overBoy==true && bonusLevel[41].overBoy==true && bonusLevel[42].overBoy==true && bonusLevel[43].overBoy==true && bonusLevel[44].overBoy==true && bonusLevel[45].overBoy==true && bonusLevel[46].overBoy==true && bonusLevel[47].overBoy==true && bonusLevel[48].overBoy==true && bonusLevel[49].overBoy==true){
          bonus_Level = false;
          endGame = true; 
      }
    }
  }
}//end levelUp

void keyPressed(){
  if (key == 'c'){
    levelOneFreeze();
    if(level_One==false && level_Two==true && level_Three==true && bonus_Level==true){
      levelTwoFreeze();
    }
    if(level_One==false && level_Two==false && level_Three==true && bonus_Level==true){
      levelThreeFreeze();
    }
    if(level_One==false && level_Two==false && level_Three==false && bonus_Level==true){
      bonusLevelFreeze();
    }

  }
  //back to the beginning
  if (key == 'r'){   
    start=false;
    level_One=true;
    level_Two=true;
    level_Three=true;
    bonus_Level=true;
    endGame=false;
    quitGame=false;
  }
  //skip to levelTwo
  if (key == 'd'){ 
    start = true;
    level_One=false;
    level_Two=true;
    level_Three=true;
    bonus_Level=true;
    endGame=false;
  }
  //skip to levelThree
  if (key == 'f'){ 
    start = true;
    level_One=false;
    level_Two=false;
    level_Three=true;
    bonus_Level=true;
    endGame=false;
  }
  //skip to bonusLevel
  if (key == 'g'){ 
    start = true;
    level_One=false;
    level_Two=false;
    level_Three=false;
    bonus_Level=true;
    endGame=false;
  }
  if (key == 'm'){
    start = true;
  }
  if (key == 'q'){
    level_One=false;
    level_Two=false;
    level_Three=false;
    bonus_Level=false;
    endGame=true;
    quitGame=true;
  }
}

Member Class:

class Member{
    float xPos = random(0,width-75);
    float yPos = random(0,height-150);
    float xSpeed, ySpeed;
    PImage [] boy = {harry, liam, louis, niall, zayn };
    PImage lad, _lad;
    boolean overBoy;
    float _xSpeed, _ySpeed;

    //Constructor
    Member(PImage lad, float xPos, float yPos){
       xSpeed = random (3.0, 5.0);
       ySpeed = random (3.0, 5.0);
       _lad = lad;
       overBoy = false;
    }//constructor  

//----------------LEVEL ONE----------------    
    void positionChange(){
      if(xPos >= width - 75|| xPos <0){
        xSpeed *= -1;
      }
      if(yPos >= height - 150 || yPos<0){
        ySpeed *= -1;
      } 
      xPos += xSpeed;
      yPos += ySpeed;
    }
    void levelOneDrawLad(){
        xPos += xSpeed;
        yPos += ySpeed; 
        _lad.resize(0,150);
        image(_lad, xPos, yPos);
    }//draw the boys
    void freezeBoy(){
      if (overBoy){
         xSpeed = 0;
         ySpeed = 0; 
       }
     }//freezeBoy

//----------------LEVEL TWO----------------    
   void positionChangeTwo(){
      if(xPos >= width - 75|| xPos <0){
        xSpeed *= -1;
      }
      if(yPos >= height - 100 || yPos<0){
        ySpeed *= -1;
      } 
      xPos += xSpeed;
      yPos += ySpeed;
    }
    void freezeBoyTwo(){
      if (overBoy){
         xSpeed = 0;
         ySpeed = 0; 
       }
     }//freezeBoy
    void levelTwoDrawLad(){
        xPos += 1.25*xSpeed;
        yPos += 1.25*ySpeed; 
        _lad.resize(0,120);
        image(_lad, xPos, yPos);
    }//draw the boys

//----------------LEVEL THREE----------------
   void positionChangeThree(){
      if(xPos >= width - 50|| xPos <0){
        xSpeed *= -1;
      }
      if(yPos >= height - 25 || yPos<0){
        ySpeed *= -1;
      } 
      xPos += xSpeed;
      yPos += ySpeed;
    } 
    void freezeBoyThree(){
      if (overBoy){
         xSpeed = 0;
         ySpeed = 0; 
       }
     }//freezeBoy
    void levelThreeDrawLad(){
        xPos += 1.5*xSpeed;
        yPos += 1.5*ySpeed; 
        _lad.resize(0,100);
        image(_lad, xPos, yPos);
    }//draw the boys

//----------------BONUS LEVEL----------------

   void positionChangeBonus(){
      if(xPos >= width - 45 || xPos <0){
        xSpeed *= -1;
      }
      if(yPos >= height - 30 || yPos<0){
        ySpeed *= -1;
      } 
      xPos += 1.75*xSpeed;
      yPos += 1.75*ySpeed;
    }
    void freezeBoyBonus(){
      if (overBoy){
         xSpeed = 0;
         ySpeed = 0; 
       }
     }//freezeBoy
   void bonusLevelDrawLad(){
        xPos += _xSpeed;
        yPos += _ySpeed; 
        _lad.resize(0,75);
        image(_lad, xPos, yPos);
    }//draw the boys

}//member

CrazyFan Class:

class CrazyFan{
    PImage crazyFan, _crazyFan;
    float fanXpos = random(0,width-75);
    float fanYpos = random(0,height-150);
    float fanXspeed = random(3.0, 5.0);
    float fanYspeed = random(3.0, 5.0); 

//Constructor
    CrazyFan(PImage crazyFan, float fanXpos, float fanYpos){
       _crazyFan = crazyFan;
    }//constructor  

   void positionChange(){
        if(fanXpos >= width - 75|| fanXpos<0){
          fanXspeed *= -1;
        }
        if(fanYpos >= height - 140 || fanYpos<0){
          fanYspeed *= -1;
        } 

        fanXpos += fanXspeed;
        fanYpos += fanYspeed;
     }

//----------------LEVEL ONE----------------  

     void levelOneDrawFan(){
      fanXpos += xSpeed;
      fanYpos += ySpeed; 
      _crazyFan.resize(0,150);
      image(_crazyFan, fanXpos, fanYpos);
    }//draw the fan

//----------------LEVEL TWO----------------     

    void levelTwoDrawFan(){
      fanXpos += xSpeed;
      fanYpos += ySpeed; 
      _crazyFan.resize(0,140);
      image(_crazyFan, fanXpos, fanYpos);
    }//draw the fan

//----------------LEVEL TWO----------------     

    void levelThreeDrawFan(){
      fanXpos += xSpeed;
      fanYpos += ySpeed; 
      _crazyFan.resize(0,130);
      image(_crazyFan, fanXpos, fanYpos);
    }//draw the fan

//----------------LEVEL TWO----------------     

    void bonusLevelDrawFan(){
      fanXpos += xSpeed;
      fanYpos += ySpeed; 
      _crazyFan.resize(0,130);
      image(_crazyFan, fanXpos, fanYpos);
    }//draw the fan 

}

 

Characteristics of Computational Media

Computers were created to make things easier. They were made so that humans didn’t have to do mindless computation. An algorithm can be written and a computer can work with enormous numbers in a faster amount of time than a human could.
Tone is one of the biggest complications in communicating through computers and communication in general. Not everyone has the same sense of humor or the same level of understanding. Someone can say something they believe to be harmless, but for some reason or another it is taken in an offensive manner by the other person. This is made even more difficult when people are communicating through by way of computers. The style of someone’s writing can be very different from how they would convey the same message if the person was standing in front of them. The generational gap also has an effect on communication. The younger generation is more casual about how they compose their messages. It’s harder to read into how serious someone is. Computational media definitely helps with artistic expression and can also aid in evoking a desired mood in the viewer.

M&Ms

eminem_mms

For this week’s assignment, I tried to find a fun data set.. I ended up finding some random set a professor took of the color distribution in packs of M&Ms. I am trying to use the average number as the radius of a circle in the window to visualize the data, but right now I’m running into a null pointer exception that I’m trying to fix.

//Colors of milk chocolate M&Ms in the fun size packages
//collected by Todd Swanson and his statistics students in 2001.
//http://www.math.hope.edu/swanson/data/mms.txt

String [][] data;
float brown, red, yellow, blue, green, orange;
MandM brownM, redM, yellowM, blueM, greenM, orangeM;
float colorXpos, colorYpos;
float brownSum, redSum, yellowSum, blueSum, greenSum, orangeSum;
int xPos, yPos;

void setup() {
  //the basics
  size(640, 280);
  
  String line[] = loadStrings("mms.csv");
  data = new String [21][6];
  for (int row=0; row < 21; row++) {
    String [] temp = new String [6];
    temp= split(line[row], ',');
    for (int column=0; column < 6; column++){
        data[row][column]= temp[column];
    }
   }
 
 //Calculating the sum
  for (int row=0; row < 21; row++) {
      brownSum += parseInt(data[row][0]);
      redSum += parseInt(data[row][1]);
      yellowSum += parseInt(data[row][2]);
      blueSum += parseInt(data[row][3]);
      greenSum += parseInt(data[row][4]);
      orangeSum += parseInt(data[row][5]);
   }

 //To visualize data: average is the radius of ellipse
 //Already know there are 21 total rows
    brown = brownSum/21;
    red = redSum/21;
    yellow = yellowSum/21;
    blue = blueSum/21;
    green = greenSum/21;
    orange = orangeSum/21;
    
    for (int i = 0; i < 6; i ++){
       brownM =new MandM (random(0,width), random(0,height), brown*15);
       redM =new MandM (random(0,width), random(0,height), red*15);
       yellowM =new MandM (random(0,width), random(0,height), yellow*15);
       blueM =new MandM (random(0,width), random(0,height), blue*15);
       greenM =new MandM (random(0,width), random(0,height), green*15);
       orangeM =new MandM (random(0,width), random(0,height), orange*15);
   }
    
 

}
 
void draw () {
    background(255);
   
    MandM [] funSize = new MandM [6];
    funSize[0] = brownM;
    funSize[1] = redM;
    funSize[2] = yellowM;
    funSize[3] = blueM;
    funSize[4] = greenM;
    funSize[5] = orangeM;
   
    for (int i=0; i<6; i++){
           if (i==0){
          fill(110,70,0);
          
        }
        if (i==1){
          fill(255,0,0);
        }
        if (i==2){
          fill(255,255,0);
        }
        if (i==3){
          fill(0,0,255);
        }
        if (i==4){
          fill(0,255,0);
        }
        if (i==5){
          fill(255,150,0);
        }
      funSize[i].drawMandM();
  }
   
}

///////
class MandM {
  
  float xPos, yPos, radius;
 
  MandM(float x, float y, float radius){
   this.xPos = x;
   this.yPos = y;
   this.radius = radius;
    
  }
  
  
  void drawMandM(){
    for(int i = 0; i < 6; i ++){
        noStroke();
        smooth();
        ellipse(xPos, yPos, radius, radius);
        noLoop();
     }  
  }
}

 

**Heart Eyes**

Screen Shot 2014-04-13 at 2.49.53 PMScreen Shot 2014-04-13 at 2.45.08 PM

For this assignment, I wanted play with something that tracks your eyes and places hearts above them, similar to the popular heart eyes emoticon.persons-0007  I tried using the eye detector codes that were up online.. But I couldn’t get any of them to work. I also tried to somehow manipulate the face detection coding.. But that also wasn’t working..  I was getting very annoyed and defeated so I left it alone for awhile and then came back to it and decided to just fiddle with the tracking color.  This however also gave me some problems.  It didn’t help that my hair color is very similar to my eye color at this point in time.. So I had to resort to covering my hair to some degree.. Work can still be done to it… It doesn’t work amazingly, but it’s decent.

 

PImage heart; 
import processing.video.*;
Capture video;
color trackColor; 

void setup() {
  size(640, 480);
  video = new Capture(this, width, height);
  video.start();
  trackColor = color(255, 0, 0);
  heart = loadImage("heart.png");

}

void draw() {
  if (video.available()) {
    video.read();
  }
  video.loadPixels();
  image(video, 0, 0);

  float worldRecord = 1000; 

  int closestX = 0;
  int closestY = 0;

  for (int x = 0; x < video.width; x ++ ) {
    for (int y = 0; y < video.height; y ++ ) {
      int loc = x + y*video.width;
      color currentColor = video.pixels[loc];
      float r1 = red(currentColor);
      float g1 = green(currentColor);
      float b1 = blue(currentColor);
      float r2 = red(trackColor);
      float g2 = green(trackColor);
      float b2 = blue(trackColor);

      float d = dist(r1, g1, b1, r2, g2, b2); 

      if (d < worldRecord) {
        worldRecord = d;
        closestX = x;
        closestY = y;
      }
    }
  }

  if (worldRecord < 1000) { 
    fill(trackColor);
    image(heart, closestX,closestY, 150, 150);
    image(heart, closestX+200,closestY, 150, 150);

  }
}

void mousePressed() {
  int loc = mouseX + mouseY*video.width;
  trackColor = video.pixels[loc];
}

 

Back to Chasing 1D… (It works now!)

tumblr_mws0yzolrR1rx97q3o2_250

For this week’s assignment I wanted to have the arduino communicate with the crazy fan who is chasing One Direction. I changed the code to make it so that the crazy fan would not be moved by the mouse, instead she would move around randomly just like the members. My goal is to catch/freeze whichever member the fan is over by setting off the sensor. This gets into knowing when an object is on top of another which I am having trouble with. I am going to keep working with it though to try to figure something out.

 

 

UPDATE:

I fixed the code! Now they all freeze separately when the sensor is pressed!

 

import ddf.minim.*;
import processing.serial.*;

Minim minim;
AudioPlayer player;
Serial myPort;

Member [] oneDirection = new Member [5];
float xPos, yPos;
float xSpeed, ySpeed;
PImage harry, liam, louis, niall, zayn; 
PImage [] boy = {harry, liam, louis, niall, zayn };
PImage crazyFan;
boolean overBoy;
int catchCounter = 0;
float fanXpos;
float fanYpos;
float fanXspeed;
float fanYSpeed;
float sensor;

void setup(){

  //--Taken from Telecommunication page on class website--
  // List all the available serial ports:
  println(Serial.list());
  // Print out the list and look for port your Microcontroller is on
  // Finding the Arduino is not easy because they have weird names on the mac and on the pc they look like COM1.
  // Ardnino is almost always the first one so you can usually use Serial.list()[0].
  String portName = Serial.list()[0];
  myPort = new Serial(this, "/dev/cu.usbmodem1411", 9600);
  myPort.readStringUntil('\n');  //clean out anything already in the buffer
  //-----

  size(800,600); 

  crazyFan = loadImage("crazyFan.png");
  fanXpos = random(0,width-75);
  fanYpos = random(0,height-150);
  fanXspeed = random(3.0, 5.0);
  fanYSpeed = random(3.0, 5.0);

  harry = loadImage("Harry_Styles.png");
  liam = loadImage("Liam_Payne.png");
  louis = loadImage("Louis_Tomlinson.png");
  niall = loadImage("Niall_Horan.png");
  zayn = loadImage("Zayn_Malik.png");

  oneDirection[0] = new Member(harry, xPos, yPos);
  oneDirection[1] = new Member(liam, xPos, yPos);
  oneDirection[2] = new Member(louis, xPos, yPos);
  oneDirection[3] = new Member(niall, xPos, yPos);
  oneDirection[4] = new Member(zayn, xPos, yPos);
  minim = new Minim(this);
  player = minim.loadFile("WMYB.mp3");
  player.play();
}

void draw(){ 

  background(255);

  for (int i = 0; i < 5; i ++){
      oneDirection[i].positionChange();
      oneDirection[i].drawLad();

  }
  crazyFan();

}  

void crazyFan(){
  crazyFan.resize(0,150);

  if(fanXpos >= width - 75|| fanXpos <0){
    fanXspeed *= -1;
  }
  if(fanYpos >= height - 150 || fanYpos < 0){
    fanYSpeed *= -1;
  } 
    fanXpos += fanXspeed;
    fanYpos += fanYSpeed; 
  image(crazyFan, fanXpos, fanYpos);
}

//--Backbone of method taken from class website--
void serialEvent(Serial _port) { //this is a callback function
  if (myPort == null) return;  //this is a hack to cover a bug where the port does not get set up in time.  
  //this says if the port is not set up yet, bail (for now.) 
  String input = myPort.readStringUntil('\n');
  if (input != null) {  //if a '\n' character has in fact now arrived
    input = input.trim();  //Take off the '\n' character
    sensor = int(input);  //Turn it into number 
   // println(sensor);
    if (sensor>=400 && sensor<=600){  
      for (int i = 0; i < 5; i ++){
        if (dist(oneDirection[i].xPos, oneDirection[i].yPos, fanXpos, fanYpos)<= 75){
          overBoy=true;
          catchCounter++;
          oneDirection[i].freeze();
        }//dist
      }

  }
  }
}

class Member{
    float xPos = random(0,width-75);
    float yPos = random(0,height-150);
    float xSpeed = random (3.0, 5.0);
    float ySpeed = random (3.0, 5.0);
    PImage [] boy = {harry, liam, louis, niall, zayn };
    PImage lad, _lad;

    //Constructor
    Member(PImage lad, float xPos, float yPos){
       _lad = lad;
    }//constructor  

    void positionChange(){
      if(xPos >= width - 75|| xPos <0){
        xSpeed *= -1;
      }
      if(yPos >= height - 150 || yPos<0){
        ySpeed *= -1;
      } 

      xPos += xSpeed;
      yPos += ySpeed;
    }

    void drawLad(){
      xPos += xSpeed;
      yPos += ySpeed; 
      _lad.resize(0,150);
      image(_lad, xPos, yPos);
    }//draw the boys

    void freeze(){
     if (overBoy){
       if (catchCounter%2==0){
          xSpeed = 0;
          ySpeed = 0; 
          System.out.println(catchCounter);
       }
      }//if over boy

    }//method

    }//member

 

So I’m obsessed with One Direction…

crazyFan

Hard to believe… But yes, I have been under the British/Irish boy band’s charm for years now..

For this week’s assignment, I started to work on a game where a crazy fan was chasing around One Direction. There’s definitely a lot more work to do with it.. I want to have something happen if the fan is over one of the boys, but nothing happens when I implement anything mouseClicked(). I’m not sure if this has anything to do with the construction of a new class and how it accesses that. I probably over complicated the code.

Here’s a video of the program running!

Screen Shot 2014-03-09 at 11.18.25 PM

import ddf.minim.*;

Minim minim;
AudioPlayer player;

Member [] oneDirection = new Member [5];
float xPos, yPos;
float xSpeed, ySpeed;
PImage harry, liam, louis, niall, zayn; 
PImage [] boy = {harry, liam, louis, niall, zayn };
PImage crazyFan;

void setup(){
  size(800,600); 
  oneDirection[0] = new Member(harry, xPos, yPos);
  oneDirection[1] = new Member(liam, xPos, yPos);
  oneDirection[2] = new Member(louis, xPos, yPos);
  oneDirection[3] = new Member(niall, xPos, yPos);
  oneDirection[4] = new Member(zayn, xPos, yPos);
  minim = new Minim(this);
  player = minim.loadFile("WMYB.mp3");
  player.play();

}

void draw(){ 
  background(255);
  for (int i = 0; i < 5; i ++){
      oneDirection[i].positionChange();
  }

  crazyFan = loadImage("crazyFan.png");
  crazyFan.resize(0,150);
  image(crazyFan,mouseX, mouseY);

  oneDirection[0].drawHarry();
  oneDirection[1].drawLiam();
  oneDirection[2].drawLouis();
  oneDirection[3].drawNiall();
  oneDirection[4].drawZayn();

  mouseClicked();

}  

class Member{
    float xPos = random(0,width-75);
    float yPos = random(0,height-150);
    float xSpeed = random (4.0, 6.0);
    float ySpeed = random (4.0, 6.0);
    PImage lad;
    PImage harry = loadImage("Harry_Styles.png");
    PImage liam = loadImage("Liam_Payne.png");
    PImage louis = loadImage("Louis_Tomlinson.png");
    PImage niall = loadImage("Niall_Horan.png");
    PImage zayn = loadImage("Zayn_Malik.png");
    PImage [] boy = {harry, liam, louis, niall, zayn };

    //Constructor
    Member(PImage lad, float xPos, float yPos){

    }//constructor  

    void positionChange(){
      if(xPos >= width - 75|| xPos <0){
        xSpeed *= -1;
      }
      if(yPos >= height - 150 || yPos<0){
        ySpeed *= -1;
      } 

      xPos += xSpeed;
      yPos += ySpeed;
    }

    void drawHarry(){
      xPos += xSpeed;
      yPos += ySpeed; 
      smooth();
      harry.resize(0,150);
      image(harry, xPos, yPos);
     }

      void drawLiam(){
      xPos += xSpeed;
      yPos += ySpeed; 
      smooth();
      liam.resize(0,150);
      image(liam, xPos, yPos);
     }

     void drawLouis(){
      xPos += xSpeed;
      yPos += ySpeed; 
      smooth();
      louis.resize(0,150);
      image(louis, xPos, yPos);
     }
      void drawNiall(){
      xPos += xSpeed;
      yPos += ySpeed; 
      smooth();
      niall.resize(0,150);
      image(niall, xPos, yPos);
     }
      void drawZayn(){
      xPos += xSpeed;
      yPos += ySpeed; 
      smooth();
      zayn.resize(0,150);
      image(zayn, xPos, yPos);
     } 

}//member

 

When It All Falls Down

Screen Shot 2014-03-03 at 12.47.32 PM

For this project I wanted to create more than one circle and have them almost fall down the screen. I had to create a circle object to do this for more than one circle to appear.

Here is a link to the video of the output

float transparency = random(80, 100);
int count = 600;
Circle [] circles;
float x,y;

void setup(){
  size (600,600);
  circles = new Circle[count];
  for (int k = 0; k < count; k++) {
      circles[k] = new Circle(x, y);
    }

}//setup

void draw(){

   background(255);
   for (int i =0; i<count; i++){
      circles[i].rainCircles();
      circles[i].draw();
     }

}//draw

class Circle {
  float x = random(0,width);
  float y;
  float radius = random(1,30);
  float speed = random (0.5, 4.0);

  // Contructor
  Circle(float x,float y) {
    x --;

  }
  void rainCircles(){
     if (y < 600 || y >=  0) {
        y+=speed;
      }
    }

  void draw() {
    float r = random(0,255);
    float g = random(0,255);
    float b = random(0,255);
    fill(r,g,b,transparency);
    noStroke();  
    ellipse(x, y, radius, radius);  
  }

}

 

 

Meow!

Screen Shot 2014-02-24 at 1.18.57 AM

 

I like cats, so I decided to make a cat!

 

void setup(){
    size(600,600);
}

void draw(){
    background(219,255,240);
    //Head
    fill(111,89,126);
    ellipseMode(CENTER);
    ellipse(300,300,400,400);

    //Left Eye
    fill(0);
    ellipseMode(CORNER);
    ellipse(220, 260, 20, 20);

    //Right Eye
    fill(0);
    ellipseMode(CORNER);
    ellipse(360, 260, 20, 20);

    //Left Ear
    fill(111, 89, 126);
    triangle(80, 80, 107, 250, 220, 118);

    //Right Ear
    fill(111, 89, 126);
    triangle(520, 80, 493, 250, 380, 118);

    //Nose
    fill(255, 167, 249);
    triangle(285, 330, 315, 330, 300, 360);

    //Whiskers
    line(150, 280, 270, 345);
    line(330, 345, 450, 280);

    line(150, 355, 270, 355);
    line(330, 355, 450, 355);

    line(150, 420, 270, 365);
    line(330, 365, 450, 420);

}

 

Urgency Alert

Using what we learned last class, I decided to use three red lights to alert the workers at the library when something needs to be checked out.  The idea is that when there are more items stacked in the box, or if there is just a heavy item, more of the red lights will light up letting the workers know.

The censor is undisturbed, indicating that nothing is in the box.
The censor is undisturbed, indicating that nothing is in the box.
One red light comes on.
One red light comes on.
Then the second.
Then the second.
Then the third!
Then the third!

IMG_4819

int brightness;
int green[] = {2,4,6};
int red[] = {13, 11, 9};

void setup(){
    //Green
    pinMode(2,OUTPUT);
    pinMode(4,OUTPUT);
    pinMode(6,OUTPUT);

    //Red
    pinMode(13,OUTPUT);
    pinMode(11,OUTPUT);
    pinMode(9,OUTPUT);

    Serial.begin(9600);
}//setup

void loop(){
    brightness = analogRead(A0);

    map(brightness, 0,255, 0, 255);

    //When the box is empty, green lights light up
    if(brightness>255){
        //Red:OFF
        for (int i=0; i<3; i++){
            digitalWrite(red[i],LOW);
        }
        //Green
        for (int i=0; i<3; i++){ 
            digitalWrite(green[i], HIGH); 
        } 
    } 

    //When there are periodicals, the green lights turn off and the red lights turn on 
    if(brightness >= 190 && brightness < 255){
        //Red
        for (int i=0; i<1; i++){
            digitalWrite(red[i], brightness);
        }
        //Green: OFF
        for (int i=0; i<3; i++){ 
            digitalWrite(green[i],LOW); } 
        } 

        if(brightness >= 100 && brightness < 190){
            //Red
            for (int i=0; i<2; i++){
                digitalWrite(red[i],brightness);
            }
            //Green: OFF
            for (int i=0; i<3; i++){ 
                digitalWrite(green[i],LOW); 
            } 
        } 

        if(brightness >= 0 && brightness < 100){
            //Red
            for (int i=0; i<3; i++){
                digitalWrite(red[i],brightness);
            }
            //Green: OFF
            for (int i=0; i<3; i++){
                digitalWrite(green[i],LOW);
            }
        }
}//loop

 

Switching It Up

When the switch is turned on, the blue light is illuminated and the red and green lights are off. When the switch is turned off, the red and green lights are on and the blue light is off.

IMG_4591

IMG_4594

IMG_4595


CODE:

void setup(){
pinMode(10,OUTPUT);
pinMode(8,OUTPUT);
pinMode(7,OUTPUT);
pinMode(4,INPUT);

}//Setup

void loop(){

if (digitalRead(4) == HIGH){
digitalWrite(10,HIGH);
digitalWrite(8,LOW);
digitalWrite(7,HIGH);

}//if HIGH

if(digitalRead(4) == LOW) {
digitalWrite(10,LOW);
digitalWrite(8,HIGH);
digitalWrite(7,LOW);

}//if LOW

Time to Check Out

I’ve been working at the NYU Law Library and part of my job includes checking periodicals/magazines/law journals out to faculty members. When an item is to be checked out, it is placed in a wooden box that can be seen from the table my coworkers and I are stationed. I had an idea to make a switch that notifies me and my coworkers when something needs to be checked out using an LED light. The items can be anything from a few pieces of paper stapled together to a large 600 page book. For my switch, I used a photocell that I soldered to two longer wires. The photocell alters the luminosity of the LED light. When the photocell is covered, the light dims. This switch accounts for the periodicals that would not weigh enough to set off a compression switch. I covered the wires with electrical tape and flattened them so the photocell can lay down in the box. When an item is put into the box, the light dims alerting my coworkers and I that something needs to be checked out and is then done in a timely manner.

IMG_4183

IMG_4184

IMG_4185