All posts by Emily Dubovoy

Final Project: Caramelldansen SUper FUn

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();
}

Timer Class:

//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;
    }
  }
}

Link to all media files:

https://drive.google.com/a/nyu.edu/folderview?id=0BxwejuremnKLYmZGTkFCU0lfRVU&usp=drive_web

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

 

Players compete to shake and dance the most. A video input captures motion and determines the changes from one screen to another, thus detecting the motion of each player.

rantrantrantrant

computer_-_happy

In the interest of my field of study, I am going to blog about the nature of “New Media” rather than “Computational Media” (which, I suppose, could be argued to be the same thing). I acquired a copy of The New Media Reader with intros by Lev Manovich and Janet Murray.

Manovich’s “New Media from Borges to HTML,” which discusses the history of the new media field. It wasn’t until the late 80s that the field really began to develop in mainstream culture. There were precursors to new media as we know it today throughout the 60’s and 70’s with Fluxus art and happenings. These emphasized infinite possibilities for an art event or object depending on which branch of narrative you followed —- a very Borgesian approach to art. New institutions dedicated to new media were opening up around Japan and Europe, which had government funding to explore technology as an art and creative endeavor. In the 80’s and early 90’s when new media technology was being further developed, America, for the most part, was still attached to the idea of artistic works being one-of-a-kind, tangible creations of single artists. In the mid-90s, universities in the western states began to introduce digital new media programs into their institutions. The thing about New Media, is that it’s difficult to define, especially at the rate with which new technology is being created and implemented.

Software design is the biggest proponent and shaping force in the new media discussion, particularly the GUI developed by Apple. It had a great impact upon modern art. With the development of computer software, artists are able to utilize such technology in augmenting their artistic visions. Putting the user against a static digital environment, like a desktop, allows infinite possibilities of where software and the web could take the user. This is where Borges’ ideas become synonymous with new media. Manovich claims that the software developers and pioneers in inventing new media technology are the true artists, who then allow others to add on and create within their vision. Manovich says that “the fact that the user can easily change everything which appears on her screen, in the process changing the internal state of a computer or even commanding reality outside of it.”

Computers were initially invented to complete algorithms, and to complete them more quickly and efficiently than a human being could. These algorithms were operated by means of machine code. This acted as a sort of “Tower of Babylon” in that it created and held a universal language that could be understood and processed in any country and on any machine. All of a sudden, walls and language barriers between countries and cultures were destroyed. Communication grew faster and faster, and tools were being created to enhance human skill. Computing act as tools in this way, where they have the ability to enhance human capabilities, while also acting as a communicative and creative entity at the same time. The digital medium is a singular concept with numerous iterations and forms. It has no start and end and weaves off into other parts of itself, but still is one cohesive thing. Networks and the web are the clearest example of this weaving and branching image of digital media. The web is a computer technology that is used as a means of distribution and can be used as an artistic medium itself.

Janet Murray is a well known as an early developer of humanities computing applications and a seminal theorist of digital media. In her essay, “Inventing the Medium,” she defined new media in as having four distinct qualities:
1. Procedural: as in completing a series of tasks efficiently.
2. Participatory: having an interactive component where humans converse with the machine.
3. Encyclopedic: the ability to sift through and store vast amounts of information. She sees this as having the most significance in influence
4. Spatial and multidimensional properties: the ability of a computer to create a new dimension of universe within itself. This is the idea of the computer as being a portal to a new realm.

Through this essay, Janet compares and contrasts Jorge Borges’s “The Garden of Forking Paths” to Vannevar Bush’s “As We May Think”, analyzing the crossovers and deviations from the humanist school of thought and the scientific approach to examining digital media. She writes that Borges is fascinated by the frivolousness of language itself, whereas Bush interprets the world not as an imprisoning labyrinth, but a complete maze that can be traversed and solved by strategically organized and collaborative effort.

Going back to Borges, Murray examines his idea of the infinite space of the Internet and cyberspace that is found in “The Garden of Forking Paths.” Having written this before the Internet, it’s interesting to think how he was inspired by a similar mindset that media theorists analyze today. Borges was “exhausted by war and exhilarated by a dawning sense of globalism.” Today, we carry access to the world in our laptops and mobile phones. How much smaller can the world become in that sense? He feared the failure of linear media to capture the structure of our thought. Borges redirects our attention to look at how we think and how our minds are working. Not linearly, that’s for sure. With the digital age, we have access to unlimited information and our choices and possibilities are infinite. “We will be the makers of the labyrinth, the gods of our own machine,” says Murray.

Our abilities to “choose our own adventure” in the digital age are neither good nor bad, just different. Technology has changed the way our brains function, just like the invention of the clock came to dictate our internal schedules. Before clocks, we would eat whenever we were hungry, sleep whenever we were tired, and work whenever we felt motivated. The clock now says that noon is lunch, 5pm is time to go home, etc. Similarly, the web has changed how we think and create. If we have a tangential thought, we can research it immediately, thus shortening our acuteness of single subjects, and creating a huge emphasis on remixing and interdisciplinary thinking. The days of long, meditative tasks and sharp focus are dwindling.

Murray makes an interesting point of how technology is a self-portrait of the culture that creates it. “The machine, like the book and the painting and the symphony and the photograph is made in our own image and reflects it back again.” I thought that was interesting to think about. As cultural lines and concepts of distance and space are dwindling and our minds change to be more like Borges’ garden, it’s interesting to think whether computers are the result of our changing minds, or if computers were the ones that changed us.

 

the fuzz

import processing.video.*;
Capture video;

// keep track of the previous frame of video
PImage prevFrame;

// threshold to qualify a pixel as being different
int threshold = 30;

void setup()
{
  size(640, 480);
  video = new Capture(this, 640, 480); 
  video.start(); 
  noStroke();

  // create a previous frame PImage
  prevFrame = new PImage(640, 480);
}

void draw()
{

  if (video.available())
  {
    // take the current frame of video and copy it into our previous frame of video
    video.loadPixels();
    prevFrame.loadPixels();
    arrayCopy(video.pixels, prevFrame.pixels);
    prevFrame.updatePixels();

    // now read a new frame of video
    video.read();
  }

  // display the current frame of the video on the stage
  image(video, 0, 0);

  // load the pixels on the stage 
  loadPixels();

  int woot = 0;

  // now we can figure out which pixels are different between the previous frame and our current frame
  video.loadPixels();
  prevFrame.loadPixels();
  for (int x = 0; x < video.width; x++)
  {
    for (int y = 0; y < video.height; y++)
    {
      // determine our location
      int location = x + y*video.width;

      // compare the pixels
      float curRed   = red(video.pixels[location]);
      float curGreen = green(video.pixels[location]);
      float curBlue  = blue(video.pixels[location]);
      float prevRed   = red(prevFrame.pixels[location]);
      float prevGreen = green(prevFrame.pixels[location]);
      float prevBlue  = blue(prevFrame.pixels[location]);
      float difference = dist(curRed, curGreen, curBlue, prevRed, prevGreen, prevBlue);
      if (difference > threshold)
      {
       //give color so we can see movement 
        pixels[location] = color(163, 255, 240);
        woot++;
      }
    }
  }

  // update the pixels on the screen
  updatePixels();

  //border

  //left
  fill(163, 255, 240);
  rect(0, 0, 20, 480);

  //right
  fill(163, 255, 240);
  rect(620, 0, 20, 480);

  //bottom
  fill(163, 255, 240);
  rect(0, 460, 640, 20);

  //top
  fill(163, 255, 240);
  rect(0, 0, 640, 20);
}

I made a simple motion detector making images out of previous frames. The change in RGB color is detected and then given a color to emphasize the change.

 

Video

Helicopter

import processing.serial.*;

Serial myPort;
PImage bg;
PImage copter;
int xpos;
int fire;

void setup() {
  size(1200, 900);
  printArray(Serial.list());
  String portName = Serial.list()[5];
  myPort = new Serial(this, portName, 9600);
  myPort.write("A"); //send any old character
  myPort.readStringUntil('\n');  
  copter = loadImage("copter.png");
  bg = loadImage("sunny-sky.jpg");
}

void draw() {
  background(bg);
  image(copter, mouseX, mouseY);
}

void mouseDragged() {
  int  mpos = int(map(mouseX, 0, width, 0, 255)); 
  println(mpos);
  myPort.write(mpos);
}
#include <Servo.h>      // include the servo library

Servo servoMotor;       // creates an instance of the servo object to control a servo

void setup() {
  Serial.begin(9600);       // initialize serial communications
  servoMotor.attach(6);  // attaches the servo on pin 2 to the servo object
  pinMode(7,OUTPUT);
}

void loop()
{
  digitalWrite(7,LOW);
  if (Serial.available() > 0) {
    int input = Serial.read();  //this waits for byte from Processing
    int servoAngle = map(input,0, 255, 0, 179);
    // move the servo using the angle from the sensor:
    digitalWrite(7,HIGH);
    servoMotor.write(servoAngle);
  }
}

Screen Shot 2014-03-29 at 7.31.15 PM

 

Here be a video

Lucky Star

For this assignment, I wanted to try a little bit of everything. I tried out the P3D mode of animation, the minim library, push and pop matrixes, and a PShape definition as well as object oriented stuff. Admittedly, some of the code is found which I then tweaked. Whatever I did copy, I made sure I understood it so that it was still a learning process(ing) lol. What was important to me this week was to just try out everything and get a grasp on what I could. This assignment has a few files to go with it, so here is a zip file of it 🙂

Screen Shot 2014-03-23 at 9.11.43 PM

Zzzzzzip

 

 

$~make it rain~$

Rain r1;

int raindrops = 50;
int checkWeather;
int whichWeather;

Rain[] drops = new Rain[raindrops]; // Declare and create the array

void setup() {
  size(600, 600);
  background(255);
  smooth();
  noStroke();

  //Loop through array to create each object
  for (int i = 0; i < drops.length; i++) {
    drops[i] = new Rain(); // Create each object
    r1 = new Rain();
  }
}

void draw() {
  fill(255, 50);
  rect(0, 0, 600, 600);
  for (int i = 0; i < drops.length; i++) {
    drops[i].fall();
  }
  if (checkWeather == 1) {
    background(184, 232, 252);
    fill(255, 255, 0);
    noStroke();
    ellipse(500, 100, 100, 100);
  }
}

void keyPressed() {
  checkWeather = 1;
}

void keyReleased() {
  checkWeather = 0;
}

class Rain {
  float x = random(600);
  float y = random(-height);

  void fall() {
    y = y + 10;
    fill(176, 227, 255, 100);
    ellipse(x, y, 10, 10);

    if (y>height) {
      x = random(600);
      y = random(-200);
    }
  }
}

 

VIDEO

 

 

dem bouncy linez

float lineX = 0;
float lineY = 0;
float xspeed = 10;
float rotation = 0;
float square1; 
float x = 0;

void setup() {
  x = 50;
  background (255);
  size(1000, 800);
  square1 = x;
}

void draw() {

  // cyan line bounce
  stroke(7, 221, 218, random(255));
  line(lineX, height, 1, 1);

  lineX = lineX + xspeed;

  if (lineX > 1000) {
    xspeed = -5;
  }

  if (lineX < 0) {
    xspeed = 5;
  }  

  // magenta line bounce
  stroke(241, 76, 119, random(255));
  line(width, lineY, 1, 1);
  lineY = lineY + xspeed;
  if (lineY > 1000) {
    xspeed = -5;
  }

  if (lineY < 0) {
    xspeed = 5;
  }

  rotation=rotation+0.06;
  fill(255, 255, 255, 100);
  noStroke();
  translate(500,400);
  rotate(rotation);
  ellipse(50, 50, 10, 10);

  rotation=rotation+0.06;
  fill(255, 255, 255, 100);
  noStroke();
  rotate(rotation);
  ellipse(100, 100, 10, 10);

  rotation=rotation+0.06;
  fill(255, 255, 255, 100);
  noStroke();
  rotate(rotation);
  ellipse(200, 200, 10, 10);

  rotation=rotation+0.06;
  fill(255, 255, 255, 100);
  noStroke();
  rotate(rotation);
  ellipse(300, 300, 10, 10);

  rotation=rotation+0.06;
  fill(255, 255, 255, 100);
  noStroke();
  rotate(rotation);
  ellipse(300, 300, 10, 10);
}

 

I made a screensaver type animation with bouncing lines with random opacity and a bullseye pattern in the corner to play with the rotate function.

Here is a sketch. 

 

Drawing Stuff

Screen Shot 2014-02-17 at 10.27.52 AM

 

size(300, 300);
background(255);   

stroke(0);
fill(0);
rect(0,0, 10, 300);

stroke(0);
fill(0);
rect(290, 0, 10, 300);

stroke(0);
fill(0);
rect(10, 0, 290, 10);

stroke(0);
fill(0);
rect(10, 290, 290, 10);

stroke(255);         
fill(108, 182, 125); 
ellipse(150, 150, 250, 250);

stroke(255);         
fill(235, 179, 90); 
ellipse(150, 150, 200, 200);

stroke(255);         
fill(191, 109, 50); 
ellipse(150, 150, 150, 150);

stroke(255);         
fill(255); 
ellipse(150, 150, 100, 100);

stroke(255);         
fill(0, 123, 111); 
ellipse(150, 150, 50, 50);

 

Stupid Bend Trick

http://youtu.be/camRmJVXcl0

I added a flex sensor into the analog input, and then outputted it into a super annoying little speaker. Ugh shut it up.

 

int speakerPin = 7;
int bend = A0;

void setup(){
  Serial.begin(9600);
  pinMode(speakerPin, OUTPUT);
}

void loop(){
  int bendVal = analogRead(bend);
  int speakerVal = bendVal * 5;
  Serial.println((String) bendVal + " -> " + (String) speakerVal);
  tone(speakerPin, speakerVal);
}

 

Ooo ooO

a tad complicado

Caleb and I made TWO separate switches with TWO separate LEDs that blinked at TWO separate speeds.

CODE//

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

void loop(){

if (digitalRead(8) == HIGH){
digitalWrite(7,HIGH);
delay(300);
digitalWrite(7,LOW);
delay(300);
}

if (digitalRead(9) == HIGH){
digitalWrite(10,HIGH);
delay(100);
digitalWrite(10,LOW);
delay(100);

}
}

 

CODE//

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

void loop(){

if (digitalRead(8) == HIGH){
digitalWrite(7,HIGH);
delay(300);
digitalWrite(7,LOW);
delay(300);
}

if (digitalRead(9) == HIGH){
digitalWrite(10,HIGH);
delay(100);
digitalWrite(10,LOW);
delay(100);

}
}