Category Archives: Uncategorized

Media and All Things Computational

 

© 2000 EyeWire Inc.

Last semester, when looking for classes in Albert, I remember what I first thought when I read the name of this class: Intro to Computational Media. My first thought was, ” I wish I was smart enough to take a computing class.” That thought then became, “maybe I AM smart enough to take a computing class.” And finally, “You know what, screw it, It doesn’t matter if I’m smart enough or what- I’m taking a computing class.” Computing has always been something that interested me. When I was five years old, I got a large white PC computer for my christmas. My twin brother got a go-kart. My older brother got a motorcycle. Today, I spend roughly 6-8 hours a day on my computer. It only makes sense to know the ins and outs. Until I decided to take this class, that was something that I had just accepted that I would potentially never know.

Computational Media is the future. Those who understand how to use it will adapt with future advancements. Those who understand the ins and outs will create those future advancements. This is something I recently realized. Thus, sparking my interest in taking this class.

I took this class for a number of reasons. One of which, is that — as with my Gallatin concentration — human interaction with computer is simply, communication. Whether it be myself writing this blog post right now or someone walking down 6th avenue taking a photo on their smart phone, a very special form of communication is occurring. That is, the asking of the computer to perform an action and the return of the computer performing an action. People tend to forget that interaction is occurring. As these devices are becoming more so extensions of the body, these interactions become as commonplace as let’s say- asking your finger to bend or asking your knee  and the other various necessary human parts to bend and stand.

This class- as with computational media- taught me how exactly that interaction occurs- through the various means and methods.

My Gallatin concentration is more so focused on how we, humans in 2014 and in the past, use technology as means of communication. I find it fascinating how we communicate with computers in order to communicate with humans. If that makes sense… If you had asked me what my concentration was prior to taking this class- it would have been something completely different. My thoughts are a bit jumbled. Well, that’s what’s on my mind right now. Kind of a stream of consciousness. Hope is doesn’t read as a bunch of 1’s and 0’s.

/rant

Cursor Craze

Here is my final project in all of its glory: Cursor Craze.

Can you get to the other side??? There’s only one way to find out!!!

I’m not exactly sure how to post a downloadable link to the full folder- but i’ll figure it out. For now, all of the images I used are in the “Media” library in WordPress.

Screen Shot 2014-05-05 at 1.42.20 PM

 

Here’s the code:

PImage  starthere;
PImage finishhere;
PImage title;
PImage rules;
PImage youlose;
PImage youlose27;
PImage youwin;
PImage pressq;

PImage almostthere;
PImage youcandoit;
PImage greatstart;
PImage keepitup;
PImage woo;

PImage greatstartcover;
PImage youcandoitcover;
PImage keepitupcover;
PImage woocover;
PImage almosttherecover;

int gap = 20;

void setup() {
  size (800, 400);
  background (204, 204, 204);
  starthere = loadImage("starhere.png");
  finishhere = loadImage("finishhere.png");
  title = loadImage("cursorcraze.png");
  rules = loadImage("mazerules2.0.png");
  youlose = loadImage("youlose2.png");
  youlose27 = loadImage("youlose27.png");
  youwin = loadImage("youwin.png");
  pressq = loadImage("pressQ.png");
  almostthere = loadImage("almostthere.png");
  youcandoit = loadImage("youcandoit.png");
  greatstart = loadImage("greatstart.png");
  keepitup = loadImage("keepitup.png");
  woo = loadImage("woo.png");
  greatstartcover = loadImage("greatstartcover.png");
  youcandoitcover= loadImage("youcandoitcover.png");
  keepitupcover = loadImage("keepitupcover.png");
  woocover = loadImage("woocover.png");
  almosttherecover = loadImage("almosttherecover.png");

  stroke (0);
  fill (0);
  //top and bottom
  //1
  rect (0, 0, gap, 160); 
  rect (0, 200, gap, 200); 
  //2
  rect (20, 0, gap, 160); 
  rect (20, 200, gap, 220); 
  //3
  rect (40, 0, gap, 140); 
  rect (40, 180, gap, 240); 
  //4
  rect (60, 0, gap, 120); 
  rect (60, 160, gap, 260); 
  //5
  rect (80, 0, gap, 100); 
  rect (80, 140, gap, 280); 
  //6
  rect (100, 0, gap, 100); 
  rect (100, 140, gap, 280); 
  //7
  rect (120, 0, gap, 120); 
  rect (120, 160, gap, 260); 
  //8
  rect (140, 0, gap, 140); 
  rect (140, 180, gap, 280); 
  //9
  rect (160, 0, gap, 160); 
  rect (160, 200, gap, 200); 
  //10
  rect (180, 0, gap, 180); 
  rect (180, 220, gap, 200); 
  //11
  rect (200, 0, gap, 200); 
  rect (200, 240, gap, 200); 
  //12
  rect (220, 0, gap, 220); 
  rect (220, 260, gap, 200);
  //13
  rect (240, 0, gap, 240); 
  rect (240, 280, gap, 200); 
  //14
  rect (260, 0, gap, 260); 
  rect (260, 300, gap, 200);
  //15
  rect (280, 0, gap, 280); 
  rect (280, 320, gap, 200); 
  //16
  rect (300, 0, gap, 300);
  rect (300, 340, gap, 200); 
  //17
  rect (320, 0, gap, 320); 
  rect (320, 360, gap, 200);
  //18
  rect (340, 0, gap, 320);
  rect (340, 360, gap, 200); 
  //19
  rect (360, 0, gap, 300);
  rect (360, 340, gap, 200);
  //20
  rect (380, 0, gap, 280);
  rect (380, 320, gap, 200); 
  //21
  rect (400, 0, gap, 260);
  rect (400, 300, gap, 200); 
  //22 
  rect (420, 0, gap, 240); 
  rect (420, 280, gap, 200);
  //23
  rect (440, 0, gap, 220); 
  rect (440, 260, gap, 200); 
  //24
  rect (460, 0, gap, 220); 
  rect (460, 260, gap, 200);
  //25
  rect (480, 0, gap, 240);
  rect (480, 280, gap, 200); 
  //26
  rect (500, 0, gap, 260);
  rect (500, 300, gap, 200); 
  //27
  rect (520, 0, gap, 280);
  rect (520, 320, gap, 200); 
  //28
  rect (540, 0, gap, 280);
  rect (540, 320, gap, 200);  
  //29
  rect (560, 0, gap, 260);
  rect (560, 300, gap, 200); 
  //30 
  rect (580, 0, gap, 240); 
  rect (580, 280, gap, 200); 
  //31
  rect (600, 0, gap, 220); 
  rect (600, 260, gap, 200); 
  //32
  rect (620, 0, gap, 200);
  rect (620, 240, gap, 220); 
  //33
  rect (640, 0, gap, 180);
  rect (640, 220, gap, 240); 
  //34
  rect (660, 0, gap, 160); 
  rect (660, 200, gap, 260);
  //35
  rect (680, 0, gap, 140);
  rect (680, 180, gap, 280); 
  //36
  rect (700, 0, gap, 120);
  rect (700, 160, gap, 300); 
  //37
  rect (720, 0, gap, 120);
  rect (720, 160, gap, 320);  
  //38
  rect (740, 0, gap, 140); 
  rect (740, 180, gap, 300);
  //39
  rect (760, 0, gap, 160);
  rect (760, 200, gap, 320); 
  //40
  rect (780, 0, gap, 160); 
  rect (780, 200, gap, 320); 

  image(starthere, 0, 200);
  image(finishhere, 700, 200);
  image(title, 210, 0);
  image(rules, 220, 70);
  image(pressq, 680, 5);
}

void draw() {

  if ((mouseX > 0 && mouseX < 20) && (mouseY < 160  || mouseY > 200)) {
    background (youlose);
  }

  else if ((mouseX > 20 && mouseX < 40 ) && (mouseY < 160 || mouseY > 200)) {
    background (youlose);
  }

  else if ((mouseX > 40 && mouseX < 60) && (mouseY < 140 || mouseY > 180)) {
    background (youlose);
  }

  else if ((mouseX > 60 && mouseX < 80) && (mouseY < 120 || mouseY > 160)) {
    background (youlose);
  }

  else if ((mouseX > 80 && mouseX < 100) && (mouseY < 100 || mouseY > 140)) {
    background (youlose);
  }

  else if ((mouseX > 80 && mouseX < 100) && (mouseY > 100 || mouseY < 140)) { 
    image(greatstart, 50, 75);
  }

  else if ((mouseX > 100 && mouseX < 120) && (mouseY < 100 || mouseY > 140)) {
    background (youlose);
  }

  else if ((mouseX > 120 && mouseX < 140) && (mouseY < 120 || mouseY > 160)) {
    background (youlose);
  }

  else if ((mouseX > 120 && mouseX < 140) && (mouseY > 120 || mouseY < 160)) {
    image (greatstartcover, 50, 75);
  }

  else if ((mouseX > 140 && mouseX < 160) && (mouseY < 140 || mouseY > 180)) {
    background (youlose);
  }

  else if ((mouseX > 160 && mouseX < 180) && (mouseY < 160 || mouseY > 200)) {
    background (youlose);
  }
  //10
  else if ((mouseX > 180 && mouseX < 200) && (mouseY < 180 || mouseY > 220)) {
    background (youlose);
  }

  else if ((mouseX > 200 && mouseX < 220) && (mouseY < 200 || mouseY > 240)) {
    background (youlose);
  }

  else if ((mouseX > 220 && mouseX < 240) && (mouseY < 220 || mouseY > 260)) {
    background (youlose);
  }

  else if ((mouseX > 240 && mouseX < 260) && (mouseY < 240 || mouseY > 280)) {
    background (youlose);
  }

  else if ((mouseX > 260 && mouseX < 280) && (mouseY < 260 || mouseY > 300)) {
    background (youlose);
  }

  else if ((mouseX > 280 && mouseX < 300) && (mouseY < 280 || mouseY > 320)) {
    background (youlose);
  }

  else if ((mouseX > 300 && mouseX < 320) && (mouseY < 300 || mouseY > 340)) {
    background (youlose);
  }

  else if ((mouseX > 320 && mouseX < 340) && (mouseY < 320 || mouseY > 360)) {
    background (youlose);
  }

  else if ((mouseX > 320 && mouseX < 340) && (mouseY > 320 || mouseY < 360)) {
    image(youcandoit, 310, 360) ;
  }

  else if ((mouseX > 340 && mouseX < 360) && (mouseY < 320 || mouseY > 360)) {
    background (youlose);
  }

  else if ((mouseX > 360 && mouseX < 380) && (mouseY < 300 || mouseY > 340)) {
    background (youlose);
  }

  else if ((mouseX > 360 && mouseX < 380) && (mouseY > 300 || mouseY < 340)) {
    image (youcandoitcover, 310, 360);
  }

  //20
  else if ((mouseX > 380 && mouseX < 400) && (mouseY < 280 || mouseY > 320)) {
    background (youlose);
  }

  else if ((mouseX > 400 && mouseX < 420) && (mouseY < 260 || mouseY > 300)) {
    background (youlose);
  }

  else if ((mouseX > 420 && mouseX < 440) && (mouseY < 240 || mouseY > 280)) {
    background (youlose);
  }

  else if ((mouseX > 440 && mouseX < 460) && (mouseY < 220 || mouseY > 260)) {
    background (youlose);
  }

  else if ((mouseX > 440 && mouseX < 460) && (mouseY > 220 || mouseY < 260)) {
    image (keepitup, 430, 180);
  }

  else if ((mouseX > 460 && mouseX < 480) && (mouseY < 220 || mouseY > 260)) {
    background (youlose);
  }

  else if ((mouseX > 480 && mouseX < 500) && (mouseY < 240 || mouseY > 280)) {
    background (youlose);
  }

  else if ((mouseX > 480 && mouseX < 500) && (mouseY > 240 || mouseY < 280)) {
    image (keepitupcover, 430, 180);
  }

  else if ((mouseX > 500 && mouseX < 520) && (mouseY < 260 || mouseY > 300)) {
    background (youlose);
  }
  //27
  else if ((mouseX > 520 && mouseX < 540) && (mouseY < 280 || mouseY > 320)) {
    background (youlose27);
  }

  else if ((mouseX > 520 && mouseX < 540) && (mouseY > 280 || mouseY < 320)) {
    image (woo, 520, 320);
  }

  else if ((mouseX > 540 && mouseX < 560) && (mouseY < 280 || mouseY > 320)) {
    background (youlose);
  }

  else if ((mouseX > 560 && mouseX < 580) && (mouseY < 260 || mouseY > 300)) {
    background (youlose);
  }

  else if ((mouseX > 560 && mouseX < 580) && (mouseY > 260 || mouseY < 300)) {
    image (woocover, 520, 320);
  }

  //30
  else if ((mouseX > 580 && mouseX < 600) && (mouseY < 240 || mouseY > 280)) {
    background (youlose);
  }

  else if ((mouseX > 600 && mouseX < 620) && (mouseY < 220 || mouseY > 260)) {
    background (youlose);
  }

  else if ((mouseX > 640 && mouseX < 660) && (mouseY < 180 || mouseY > 220)) {
    background (youlose);
  }

  else if ((mouseX > 660 && mouseX < 680) && (mouseY < 160 || mouseY > 200)) {
    background (youlose);
  }

  else if ((mouseX > 680 && mouseX < 700) && (mouseY < 140 || mouseY > 180)) {
    background (youlose);
  }

  else if ((mouseX > 700 && mouseX < 720) && (mouseY < 120 || mouseY > 160)) {
    background (youlose);
  }

  else if ((mouseX > 700 && mouseX < 720) && (mouseY > 120 || mouseY < 160)) {
    image(almostthere, 690, 85);
  }

  else if ((mouseX > 720 && mouseX < 740) && (mouseY < 120 || mouseY > 160)) {
    background (youlose);
  }

  else if ((mouseX > 740 && mouseX < 760) && (mouseY < 140 || mouseY > 180)) {
    background (youlose);
  }

  else if ((mouseX > 740 && mouseX < 760) && (mouseY > 140 || mouseY < 180)) {
    image (almosttherecover, 690, 85);
  }

  //final 2 boxes
  else if ((mouseX > 760 && mouseX < 780) && (mouseY < 160 || mouseY > 200)) {
    background (youlose);
  }
  //40
  else if ((mouseX > 780 && mouseX < 800) && (mouseY < 160 || mouseY > 200)) {
    background (youlose);
  }

  else if ((mouseX > 760 && mouseX < 780) && (mouseY > 160 || mouseY < 200)) {
    background (youwin);
  }

  else if ((mouseX > 780 && mouseX < 800) && (mouseY > 160 || mouseY < 200)) {
    background (youwin);
  }

  if (keyPressed) {
    if (key == 'q') {
      background (204, 204, 204);
      stroke (0);
      fill (0);
      //top and bottom
      //1
      rect (0, 0, gap, 160); 
      rect (0, 200, gap, 200); 
      //2
      rect (20, 0, gap, 160); 
      rect (20, 200, gap, 220); 
      //3
      rect (40, 0, gap, 140); 
      rect (40, 180, gap, 240); 
      //4
      rect (60, 0, gap, 120); 
      rect (60, 160, gap, 260); 
      //5
      rect (80, 0, gap, 100); 
      rect (80, 140, gap, 280); 
      //6
      rect (100, 0, gap, 100); 
      rect (100, 140, gap, 280); 
      //7
      rect (120, 0, gap, 120); 
      rect (120, 160, gap, 260); 
      //8
      rect (140, 0, gap, 140); 
      rect (140, 180, gap, 280); 
      //9
      rect (160, 0, gap, 160); 
      rect (160, 200, gap, 200); 
      //10
      rect (180, 0, gap, 180); 
      rect (180, 220, gap, 200); 
      //11
      rect (200, 0, gap, 200); 
      rect (200, 240, gap, 200); 
      //12
      rect (220, 0, gap, 220); 
      rect (220, 260, gap, 200);
      //13
      rect (240, 0, gap, 240); 
      rect (240, 280, gap, 200); 
      //14
      rect (260, 0, gap, 260); 
      rect (260, 300, gap, 200);
      //15
      rect (280, 0, gap, 280); 
      rect (280, 320, gap, 200); 
      //16
      rect (300, 0, gap, 300);
      rect (300, 340, gap, 200); 
      //17
      rect (320, 0, gap, 320); 
      rect (320, 360, gap, 200);
      //18
      rect (340, 0, gap, 320);
      rect (340, 360, gap, 200); 
      //19
      rect (360, 0, gap, 300);
      rect (360, 340, gap, 200);
      //20
      rect (380, 0, gap, 280);
      rect (380, 320, gap, 200); 
      //21
      rect (400, 0, gap, 260);
      rect (400, 300, gap, 200); 
      //22 
      rect (420, 0, gap, 240); 
      rect (420, 280, gap, 200);
      //23
      rect (440, 0, gap, 220); 
      rect (440, 260, gap, 200); 
      //24
      rect (460, 0, gap, 220); 
      rect (460, 260, gap, 200);
      //25
      rect (480, 0, gap, 240);
      rect (480, 280, gap, 200); 
      //26
      rect (500, 0, gap, 260);
      rect (500, 300, gap, 200); 
      //27
      rect (520, 0, gap, 280);
      rect (520, 320, gap, 200); 
      //28
      rect (540, 0, gap, 280);
      rect (540, 320, gap, 200);  
      //29
      rect (560, 0, gap, 260);
      rect (560, 300, gap, 200); 
      //30 
      rect (580, 0, gap, 240); 
      rect (580, 280, gap, 200); 
      //31
      rect (600, 0, gap, 220); 
      rect (600, 260, gap, 200); 
      //32
      rect (620, 0, gap, 200);
      rect (620, 240, gap, 220); 
      //33
      rect (640, 0, gap, 180);
      rect (640, 220, gap, 240); 
      //34
      rect (660, 0, gap, 160); 
      rect (660, 200, gap, 260);
      //35
      rect (680, 0, gap, 140);
      rect (680, 180, gap, 280); 
      //36
      rect (700, 0, gap, 120);
      rect (700, 160, gap, 300); 
      //37
      rect (720, 0, gap, 120);
      rect (720, 160, gap, 320);  
      //38
      rect (740, 0, gap, 140); 
      rect (740, 180, gap, 300);
      //39
      rect (760, 0, gap, 160);
      rect (760, 200, gap, 320); 
      //40
      rect (780, 0, gap, 160); 
      rect (780, 200, gap, 320); 

      image(starthere, 0, 200);
      image(finishhere, 700, 200);
      image(title, 210, 0);
      image(rules, 220, 70);
      image(pressq, 680, 5);
    }
  }
}

Food for thought:

– would be great to add a timer

– would be even greater to have the map move

– Different levels would be awesome

 

 

Big Data, Little Brain

I really wish my brain could wrap around this idea of Big Data and how exactly to use it. I really do see the importance of it all. Over the next few years I will make it a goal of mine. In the meantime, I can just pretend that I understand it and sound smart to my friends.

I’m still extremely interested in this whole Wikipedia Philosophy thing. After looking more at Wikipedia’s API– the more I understand the importance of APIs as a whole as well as the wealth of information that Wikipedia is.

I decided to make a little mock up of what a possible data visualization of the links to “Philosophy” would be:

philosophy2

 

Would be pretty cool….

In 2 years time, I hope to be able to make the real deal. High hopes! High rewards! Yeeehaw!

 

CaramellDansen Shake!

super fun girls time presents:

shake-your-booty-fun! (abi, emily, ieva, and nicole)

press ‘1’ to start player 1’s round. press ‘2’ to start player 2’s round. press ‘w’ to see who won. press ‘q’ to restart and play again!

Screenshot of gameplay
Screenshot of gameplay
Winner's screen!
Winner’s screen!

 

link to all the media files-

https://drive.google.com/folderview?id=0B-scoLsJ5PclSy1ZYmJtQ1lPQ2c&usp=sharing

import processing.video.*;
import ddf.minim.*;

Capture video;
PImage prevFrame;

Movie instructionsScreen;
Movie player1_screen;
Movie player2_screen;
Movie scoreBar1;
Movie scoreBar2;
Movie player1_wins;
Movie player2_wins;
Movie stop1;
Movie stop2;

Minim minim;
AudioPlayer player;

float threshold = 50;
int counter = 0;
int counter2 = 0;
boolean round1 = false;
boolean round2 = false;

float ypos1, ypos2; //location of score bar

Timer theStartTimer1;
Timer theGameTimer1;
Timer theStartTimer2;
Timer theGameTimer2;
boolean gameStart1 = false;
boolean gameStart2 = false;

void setup() {
  size(1280, 720);
  smooth();
  noStroke();
  video = new Capture(this, width, height);
  video.start();
  prevFrame = createImage(video.width, video.height, RGB);

  instructionsScreen = new Movie(this, "instructions.mov");
  player1_screen = new Movie(this, "player1_screen.mov");
  player2_screen = new Movie(this, "player2_screen.mov");
  scoreBar1 = new Movie(this, "score_bar.mov");
  scoreBar2 = new Movie(this, "score_bar.mov");
  player1_wins = new Movie(this, "player1_wins.mov");
  player2_wins = new Movie(this, "player2_wins.mov");
  stop1 = new Movie(this, "stop1.mov");
  stop2 = new Movie(this, "stop2.mov");

  minim = new Minim(this);
  player = minim.loadFile("Caramelldansen.wav");

  theStartTimer1 = new Timer(6000); 
  theGameTimer1 = new Timer (26000); //actual gameplay is 20sec
  theStartTimer2 = new Timer(6000);
  theGameTimer2 = new Timer (26000);
}

void draw() {
  image(instructionsScreen, 0, 0);
  instructionsScreen.play();

  if (gameStart1 == true) {
    instructionsScreen.stop();
    player.play();

    //round 1
    if (theStartTimer1.timeOver()) {
      if (theGameTimer1.timeOver()) {
        image(stop1, 0, 0);
        stop1.play();
        round1 = true;
      }
      else {
        image(player1_screen, 0, 0);
        player1_screen.play();
        theGameTimer1.countDown();

        textSize(height/10);
        fill(255, 0, 255);
        text (counter, width/30, height/10);
        textSize(height/10);
        fill(0, 255, 255);
        text (counter2, width-width/7.5, height/10);

        // Capture video
        if (video.available()) {
          // Save previous frame for motion detection
          prevFrame.copy(video, 0, 0, video.width, video.height, 0, 0, video.width, video.height);
          prevFrame.updatePixels();
          video.read();
        }

        loadPixels();
        video.loadPixels();
        prevFrame.loadPixels();

        float totalMotion = 0;

        // Sum the brightness of each pixel
        for (int i = 0; i < video.pixels.length; i ++ ) {
          // Step 2, what is the current color
          color current = video.pixels[i];

          // Step 3, what is the previous color
          color previous = prevFrame.pixels[i];

          // Step 4, compare colors (previous vs. current)
          float r1 = red(current);
          float g1 = green(current);
          float b1 = blue(current);
          float r2 = red(previous);
          float g2 = green(previous);
          float b2 = blue(previous);

          // Motion for an individual pixel is the difference between the previous color and current color.
          float diff = dist(r1, g1, b1, r2, g2, b2);
          // totalMotion is the sum of all color differences.
          totalMotion += diff;
        }

        // averageMotion is total motion divided by the number of pixels analyzed.
        float avgMotion = totalMotion / video.pixels.length;

        // average motion
        smooth();
        noStroke();
        fill(0);
        counter += avgMotion/20;

        float ypos = map (counter, 0, 1200, 0, height);
        image(scoreBar1, width/32, height-ypos);
        ypos1 = height-ypos;
        scoreBar1.loop();
      }
    } 
    else
    {
      image(player1_screen, 0, 0);
      player1_screen.play();
    }
  }

  //round 2
  if (gameStart2 == true) {
    player1_screen.stop();

    if (theStartTimer2.timeOver()) {
      if (theGameTimer2.timeOver()) {
        image(stop2, 0, 0);
        stop2.play();
      }
      else {
        image(player2_screen, 0, 0);
        player2_screen.play();
        theGameTimer2.countDown();
        textSize(height/10);
        fill(255, 0, 255);
        text (counter, width/30, height/10);
        textSize(height/10);
        fill(0, 255, 255);
        text (counter2, width-width/7.5, height/10);
        image(scoreBar1, width/32, ypos1);

        // Capture video
        if (video.available()) {
          // Save previous frame for motion detection
          prevFrame.copy(video, 0, 0, video.width, video.height, 0, 0, video.width, video.height);
          prevFrame.updatePixels();
          video.read();
        }

        loadPixels();
        video.loadPixels();
        prevFrame.loadPixels();

        float totalMotion = 0;

        // Sum the brightness of each pixel
        for (int i = 0; i < video.pixels.length; i ++ ) {
          // Step 2, what is the current color
          color current = video.pixels[i];

          // Step 3, what is the previous color
          color previous = prevFrame.pixels[i];

          // Step 4, compare colors (previous vs. current)
          float r1 = red(current);
          float g1 = green(current);
          float b1 = blue(current);
          float r2 = red(previous);
          float g2 = green(previous);
          float b2 = blue(previous);

          // Motion for an individual pixel is the difference between the previous color and current color.
          float diff = dist(r1, g1, b1, r2, g2, b2);
          // totalMotion is the sum of all color differences.
          totalMotion += diff;
        }

        // averageMotion is total motion divided by the number of pixels analyzed.
        float avgMotion = totalMotion / video.pixels.length;

        // average motion
        smooth();
        noStroke();
        fill(0);
        counter2 += avgMotion/20;

        float ypos2A = map (counter2, 0, 1200, 0, height);
        image(scoreBar2, width- width/7, height-ypos2A);
        ypos2 = height-ypos2A;
        scoreBar2.loop();
      }
    } 
    else
    {
      image(player2_screen, 0, 0);
      player2_screen.play();
    }
  }

  if (round1 == true && round2 == true) {
    //instructionsScreen.stop();
    player1_screen.stop();
    player2_screen.stop();
    //image(scoreBar1, width/32, ypos1);
    image(scoreBar2, width - width/7, ypos2);

    //if player2 wins
    if (counter2 > counter) {
      image(player2_wins, 0, 0);
      player2_wins.play();
    }
    //if player1 wins
    if (counter > counter2) {
      image(player1_wins, 0, 0);
      player1_wins.play();
    }
  }
}

void keyPressed() {
  if (key == '2') {
    gameStart2 = true;
    theStartTimer2.start();
    theGameTimer2.start();
  }
  else {
    gameStart2 = false;
  }

  if (key == '1') {
    gameStart1 =  true;
    theStartTimer1.start();
    theGameTimer1.start();
  } 

  if (key == 'w') {
    round2 = true;
  }

  if (key == 'q') {
    gameStart1 = false;
    gameStart2 = false;
    round1 = false;
    round2 = false;
    counter2 = 0;
    counter = 0;
    ypos1 = height;
    ypos2 = height;
    scoreBar1.stop();
    scoreBar2.stop();
  }
}

void movieEvent(Movie m) {
  m.read();
}
//New Class

PFont font;

class Timer {
  int savedTime;
  int totalTime;
  int countDown;
  int passedTime;
  int screenSeconds;

  Timer(int temp_totalTime) {
    totalTime = temp_totalTime;

  }

  void start() {
    savedTime = millis();
  }

  void countDown(){
    screenSeconds = passedTime / 1000;
     countDown = 26 - screenSeconds;
    font = loadFont("KarmaSuture.vlw");
    fill(50, 255, 0);
    textFont(font, 100);
    text(countDown, width/2.2, height/7); 
  }

  boolean timeOver() {
  passedTime = millis() - savedTime;
    if (passedTime > totalTime) {
      return true;
    }    
    else {
      return false;
    }
  }
}

 

Rainy Day Flower Video

For my final, I went back and forth between a few ideas, but ultimately, I decided to address the two elements that I had wanted to try but hadn’t figured out yet: movie and minim. The video is simple because my intention was to include more opportunities for user interaction, but at least it is functional. I had to make the choice between something that works and something that is complex…and I chose something that works. I used some random video that I shot the other day on an iPhone (this is not the video I had originally planned to use) because it is pretty and simple. I chose Youth Lagoon’s “17” to accompany it, as both the movie and the music are nice and calm. To add a bit more complexity, I added a mouseClick function, which simultaneously pauses the movie and the music. This turns the project into a music video player! When the mouse is released, both the movie and music return. I have a key pressed function that evaluates the brightness of the video and then colors the sky blue while the key is pressed to give the appearance of a rainy day/thunderstorm. For this part, I hoped to manipulate the video by tracking someone’s movement with the webcam, but ultimately, I couldn’t figure out how to do this. Thought that I could change the pitch and/or volume of the music that way, or the playback speed of the video. Since I struggled to translate the data from the computer’s vision into manipulation of the video on screen, I replaced that portion with a keyPressed function so when the spacebar is pressed, the video speeds up and the sky turns blue like a rainstorm! I know this looks like a pretty simple project, but for my final,  I really wanted to make something entirely functional and visually appealing.

import processing.video.*;
Movie myMovie;

import ddf.minim.*;
Minim minim;
AudioPlayer song;

void setup() {
  size(960, 540);
  myMovie = new Movie(this, "TreeCircle.mov");
  myMovie.loop();

  minim=new Minim(this);
  song= minim.loadFile("17.mp3");
  song.play();

}

void draw() {
  image(myMovie, 0,0, 960, 540);

    }

void mousePressed() {
  myMovie.pause();
  song.pause();
}

void mouseReleased() {
  myMovie.play();
  song.play();

}

void keyPressed() {
 for (int i = 0; i < myMovie.pixels.length;  i++) {  //you can ask the pixel array how long it is
    if ( brightness(myMovie.pixels[i]) > 200) {  //check the brightness of the pixel
      myMovie.pixels[i] = color(0, 200, 250,150);  //
      myMovie.speed(4.0);
    }}}

// Called every time a new frame is available to read
void movieEvent(Movie m) {
  m.read();

}

void stop() {
  song.close();
  minim.stop();

  super.stop();
}

 

Parsing from “I TRIED EATING GOURMET DOG FOOD, AND NOW I HATE MYSELF”

 

 

I read this Vice article and figured it might be fun to parse. I enjoyed playing with the aesthetic features in particular, so it’s quite similar to the example we worked with in class, but I gained a more solid understanding of the code since I was using something that already works. I guess the moral of the story here is don’t eat dog food, even if it’s gourmet. To emphasize that point, I used a photo from the article for the background image. dogfoodeater

String[] vice;    // The array to hold all of the text
PImage dogfood;
PImage ew;
PImage dog;
boolean pressed=true;
String delimiters = " ,.?!;:[]";

IntDict words;

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

  // Load vice into an array of strings
  String url = ("dogfoodeater.rtf");
  String[] rawtext = loadStrings(url);//comes in as an array (reads every line as seperate array)

  // Join the big array together as one long string
  String everything = join(rawtext, "dogfoodeater.rtf" );//undoes the array-ness of it and makes it one big thing

  // All the lines in vice are first joined as one big String and then split up into an array of individual words. 
  // Note the use of splitTokens() since we are using spaces and punctuation marks all as delimiters.  
  vice = splitTokens(everything, delimiters);

  // Make a new empty dictionary every entry has a name and a value
  words = new IntDict();

  for (int i = 0; i < vice.length; i++) {
    String s = vice[i].toLowerCase();
    words.increment(s); 
  }

  // Sort so that words that appear most often are first
  words.sortValuesReverse();

  dogfood=loadImage("http://assets.vice.com/content-images/contentimage/147711/DSC03667.jpg");
  dogfood.resize(600,600);
  ew=loadImage("http://assets.vice.com/content-images/contentimage/147713/DSC03691.jpg");
  ew.resize(600,600);
  dog=loadImage("http://www.iluvpugdogs.com/wp-content/uploads/2013/02/7.jpg");
  dog.resize(70,70);

 if (pressed==true){
    background(dogfood);
  }
  else {
    pressed=false;
    background(ew);
  }
}

void draw() {
image(dog, mouseX,mouseY);

background(dogfood);

 if (pressed==true){
    background(dogfood);
  }
  else {
    pressed=false;
    background(ew);
  }

  // Display the text and total times the word appears
  int h = 20;
  String[] keys = words.keyArray();

  for (int i = 0; i < height/h; i++) {
    String theword = keys[i];
    int count = words.get(theword);

    fill(mouseX, mouseY, count/.3, 150);
    rect(20, i*20, count*5, h-4);
    fill(255);
    text(theword, 30+count*5,i*h+h/2);
    stroke(255);

   image(dog, mouseX,mouseY);
  }
}

 

Space Shooter (in the works)

hello friends

this week started working on a game that includes computer vision as the controller. this is still in the works, but i’ll post the most recent code i have. basically it’s a derivative of the oldschool game ‘pong’, where the player is a red space ship trying to destroy the black enemy spacecraft (the death star?) by catching the balls and throwing them back at the enemy. The balls shoot randomly from the enemy every half second. If the player can catch a ball by pressing a button when a ball hits them. However, if the ball hits the player when they are not pressing the button, then the player will lose a life.

so far, i have parts of this game working, but the video tracking is a bit off. i’m trying to have the video load only for the beginning of the game so the user can click a tracking marker, and then once the game starts, remove the video so it won’t be distracting during the game. (maybe kinect would work better for this? and/or ‘hand’ tracking)

Screen Shot 2014-04-14 at 1.56.03 PM

 

//tracking the average pixel makes it shake less
import processing.video.Capture;
Capture cam;// regular processing libary
int threshold = 20; //255 is white, 0 is black
int aveX, aveY; //this is what we are trying to find
float objectR =255;
float objectG = 0;
float objectB = 0;

Ship theShip;
Enemy theEnemy;
Timer theTimer;
Timer theVideoTimer;
ArrayList theBall;

void setup() {
  size(640, 480);
  println(Capture.list());
  cam = new Capture(this, width, height);
  cam.start();
  theTimer = new Timer(500);
  theVideoTimer = new Timer (5000);
  theTimer.start();
  theBall = new ArrayList();
  theShip = new Ship();
  theEnemy = new Enemy(200);
}

void draw() {

  if (theTimer.timeOver()) {
    theBall.add(new Ball (20));
    theTimer.start();
  }

  for (int i = 0; i < theBall.size(); i++) {
    Ball b = (Ball) theBall.get(i);
    if (theShip.intersect(b)) {
      println("hey");
      b.change();
    }
    //b.Print();
    b.move();
    b.display();
  }

  if (cam.available()) {
    cam.read();
    int totalFoundPixels= 0;  
    int sumX = 0; 
    int sumY = 0;

    for (int row = 0; row < cam.height; row++) {
      for (int col = 0; col < cam.width; col++) {

        int offset = row * cam.width + col;
        int thisColor = cam.pixels[offset];

        float r = red(thisColor);
        float g = green(thisColor);
        float b = blue(thisColor);

        float diff = dist(r, g, b, objectR, objectG, objectB);

        if (diff < threshold) { 
          sumX = sumX + col;
          sumY= sumY + row;
          totalFoundPixels++;
        }
      }
    }

    //allows user to click tracking color, then supposed to remove video
       if (theVideoTimer.timeOver()) {
        background(157, 247, 239);

  } else
  {
      image(cam, 0, 0);
  }

    if (totalFoundPixels > 0) {
      aveX = sumX/totalFoundPixels;
      aveY = sumY/totalFoundPixels;

      for (int i = 0; i < theBall.size(); i++) {
        Ball b = (Ball) theBall.get(i);
        if (theShip.intersect(b)) {
        }
      }
    }
  }
   theShip.display();
   theEnemy.display();
}

void mousePressed() {
  //if they click, use that picture for the new thing to follow
  int offset = mouseY * cam.width + mouseX;
  //pull out the same pixel from the current frame 
  int thisColor = cam.pixels[offset];

  //pull out the individual colors for both pixels
  objectR = red(thisColor);
  objectG = green(thisColor);
  objectB = blue(thisColor);
  println("Chasing new color  " + objectR + " " + objectG + " " + objectB);
}
class Ball {
  float r; //radius of ball
  float theta; //degree of shot
  float xSpeed, ySpeed;                                                                      
  float x = width/2;
  float y = height/2;
  boolean change = false;

  Ball (float tempR) {
    r = tempR;
    xSpeed = 1;
    ySpeed = 1;
    theta = int (random(0, 360));
  }
  void move() {
    xSpeed = cos(radians(theta));
    ySpeed = sin(radians(theta));
    if (change == true){
      x -= xSpeed;
      y -= ySpeed;
    }else{

    x += xSpeed;
    y += ySpeed;
  }
  }

  void display() {
    if (change == true) {
      stroke(255, 0, 0);
    } 
    else {
      stroke(0, 0, 255);
    }

    fill(255);
    strokeWeight(3);
    //stroke(0, 0, 255);
    ellipse(x, y, r, r);
  }

  void Print() {
    println(theta);
  }

  void disappear() {
    if (x < 0 || x > width) {
      x = 2 * width;
    }
    if (y < 0 || y > height) {
      y = 2 * height;
    }
  }

  void change() {
    change = true;
  }
}

 

class Enemy {
  float e; //enemy radius

    Enemy(float tempE) {
    e = tempE;
  }

  void display() {
    noStroke();
    fill (0);
    ellipse(width/2, height/2.5, e, e);
  }
}

 

class Ship {
  float s; //length of triangle side
  float z; //distance away from enemy cener

  Ship() {
    z = 175;
    s = 25;
  }

  void display() {
    fill (255, 0, 0);
    noStroke();
    float rotation = -(width-aveX-10) *1.2;
    pushMatrix();
    translate(width/2, height/2.5);
    rotate (radians(rotation));
    shapeMode(CENTER);
    triangle (-s, z+s*sqrt(3), s, z+s*sqrt(3), 0, z);
    popMatrix();
  }

  boolean intersect(Ball b) {
    float rotation = radians(-mouseX * 1.2);
        float distance = dist(aveX-10, aveY-10, b.x, b.y);
    println (width-rotation);
    if (distance < 10) {
      return true;
    } 
    else
      return false;
  }
}

 

class Timer {
  int savedTime;
  int totalTime;

  Timer(int temp_totalTime) {
    totalTime = temp_totalTime;
  }

  void start() {
    savedTime = millis();
  }

  boolean timeOver() {
    int passedTime = millis() - savedTime;
    if (passedTime > totalTime) {
      return true;
    }    
    else {
      return false;
    }
  }
}

 

 

Truco estúpido de la mascota

My stupid pet trick used the photosensor to determine how many LED’s should be lit. Pretty simple concept, but I’m proud of myself for figuring out how to code it into the Arduino. Check out the video.

IMG_0076

Though I’m not sure how practical something like this is, I imagine we can come up with some cool ideas on how to extend this project in class. I was thinking:

-Auto-adjustment for darkness of an environment (think about how an iPhone can auto-adjust its brightness)

-LED variation based on a different input e.g. sound, number of tweets, weight in an elevator (this how amplifiers/receivers have LEDs that indicate decibel output of different parts of a sound)

Here is the nesty code:

int brightness;

void setup(){
  Serial.begin(9600);
  pinMode(11,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(3,OUTPUT);
}

void loop(){

 brightness = analogRead(A0);
 Serial.println(brightness);
 map(brightness,35,270,0,255);
 if(brightness<255){
   digitalWrite(11,HIGH);}
 if(brightness<205){
   digitalWrite(10,HIGH);}
 if(brightness<180){
   digitalWrite(9,HIGH);}
 if(brightness<160){
   digitalWrite(6,HIGH);}
 if(brightness<120){
   digitalWrite(5,HIGH);}
 if(brightness<100){
   digitalWrite(3,HIGH);}
 if(brightness>100){
    digitalWrite(3,LOW);}
 if(brightness>120){
    digitalWrite(5,LOW);}
 if(brightness>160){
    digitalWrite(6,LOW);}
 if(brightness>180){
    digitalWrite(9,LOW);}
 if(brightness>205){
    digitalWrite(10,LOW);}
 if(brightness>255){
    digitalWrite(11,LOW);}
 }

 

 

Graphite Variable Resistor

Hi!

This week I created a switch that is itself also a variable resistor.

It turns out that graphite is conductible. So I hooked up an LED and watched how I got a different brightness reading on the LED depending how far away my power and ground wires were to each other. It makes sense, the farther away the two wires were, the more resistance and therefore the less output on the LED. The closer the two wires were to each other, the less resistance, and the brighter the LED became.

This is possible without software because it is totally controlled my where the power and ground are physically to each other. The next step would to be figuring out how I could create an interesting result to how much output is created by the LED.

Also, graphite is hardly conductive, it took a lot of effort to create a conductible image. I’m wondering if I can create a variable resistor from graphite based on the intensity of graphite…?

 

Movie on 2-24-14 at 12.36 PM

 

Apartment and the Sun

This week, I really enjoyed getting to work with Processor (though my artistic abilities are clearly sub-par)! To begin, I just started making basic shapes, which resulted in a very simple looking apartment building. However, this actually took quite a bit of time initially, because I suck at math and the windows were rather tricky! Afterwards, I just messed around by exploring the Processing Language Reference and made a little outer space scene that includes a rotating sphere, a.k.a. “the sun,” as well as the first three planets in our solar system (Mercury, Venus, and Earth). They sort of revolve around the sun in some sort of bizarre way when you drag your mouse across it, but to create this, I mostly copied and pasted the example code and then played with the colors and placement of the shapes, so I still have no clue how the rotation, etc. actually works.

The code for the apartment building is here:

size(640,360);
background(150,150,230);

stroke(255,200,10);
fill(255,255,0);
ellipse(450,50,50,50);

stroke(255,0,0);
fill(255,255,0);
rect(170,60,200,290);

fill(0,150,200,20);
rect(185,270,40,80);

fill(255);
stroke(0,0,255);
rect(250,280,60,30);

stroke(0,0,255);
line(280,280,280,310);

stroke(0,0,255);
line(250,295,310,295);

stroke(255,0,0);
fill(0,150,200,20);
rect(185,170,40,80);

fill(255);
stroke(0,0,255);
rect(250,190,60,30);

stroke(0,0,255);
line(280,190,280,220);

stroke(0,0,255);
line(250,205,310,205);

stroke(255,0,0);
fill(0,150,200,20);
rect(185,70,40,80);

fill(255);
stroke(0,0,255);
rect(250,90,60,30);

stroke(0,0,255);
line(280,90,280,120);

stroke(0,0,255);
line(250,105,310,105);

 

And here is the code for the rotating sphere/planet scene:

void setup() {
size(640, 360, P3D);
}

void draw() {
background(100,0,240);
stroke(200,100, 0);
translate(150, 150, 0);
rotateX(mouseY * 0.05);
rotateY(mouseX * 0.05);
fill(mouseX * 10, 200, 100);
sphereDetail(mouseX / 4);
sphere(140);

stroke(200,100, 0);
translate(500, 200, 0);
rotateX(mouseY * 0.05);
rotateY(mouseX * 0.05);
fill(mouseX * 120, 10, 100);
sphereDetail(mouseX / 4);
sphere(40);

stroke(0);
fill(150);
rect(350,120,20,10);

stroke(100,100,0);
fill(200,200,0);
ellipse(500,50,50,50);

stroke(20,100,250);
fill(0,200,200);
ellipse(580,80,60,60);

}

 

 

 

 

 

Frère Jacques

 

For my stupid pet trick I decided to make an alarm. Lately I’ve been making an effort to wake up earlier every day so it’s easier to do on days I have to, circadian rhythm, all that jazz. Since spring finally seems to me coming (sort of) and the days are getting longer, this alarm will be triggered by the sunrise.

It’s a pretty basic setup: 2 LEDs, a piezo buzzer and a photo cell. When light hits the photocell (assuming daylight, though in this case I used the brightness on my computer), first a yellow LED is triggered, as a warning that it’s time to wake up. Once more light hits, the red LED is activated. When it is finally bright, and time to get up, the piezo plays the tune of Frère Jaques, a song about waking up, which also happens to feature just a few simple notes.

Here is the code, it’s a little long-winded because of the song, but easy to follow. In it, I use two ways of initializing the variable and a few if/else statements.

int lights;
int sound = 9;

void setup(){
  Serial.begin(9600);
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(9,OUTPUT);
}

void loop(){
lights = analogRead(A5);
 Serial.println(lights);
 map(lights,490,890,0,255);
  if (lights>50) {digitalWrite(6,HIGH);
 }else{ digitalWrite(6,LOW);
 }
 if (lights>20) {digitalWrite(7,HIGH);  
 }else{ digitalWrite(7,LOW);
 }
 if (lights>250) {tone(sound,261,500);//c 
 delay(500);
 noTone(sound);
 tone(sound, 294,500);//d
 delay(500);
 noTone(sound);
 tone(sound,329,500);//e
 delay(500);
 noTone(sound);
 tone(sound,261,500);//c
 delay(500);
 tone(sound,261,500);//c 
 delay(500);
 noTone(sound);
 tone(sound, 294,500);//d
 delay(500);
 noTone(sound);
 tone(sound,329,500);//e
 delay(500);
 noTone(sound);
 tone(sound,261,500);//c
 delay(550);
 noTone(sound);
 tone(sound,329,500);//e
 delay(500);
 noTone(sound);
 tone(sound,349,500);//f
 delay(500);
 noTone(sound);
 tone(sound,392,500);//g
  delay(550);
 noTone(sound);
 tone(sound,329,500);//e
 delay(500);
 noTone(sound);
 tone(sound,349,500);//f
 delay(500);
 noTone(sound);
 tone(sound,392,500);//g
 delay(900);

 }else{ digitalWrite(7,LOW);
 }

}

http://youtu.be/UyBiVwfu2ZY