User Tools

Site Tools


cs276:a16:cl_dm_p2

Cassidy Gibson && Daniel Molder

If you would like to see the photos on hive, this is the link to it: Click Here

file: Project 2

/* Cassidy Gibson and Daniel Molder
*
* This is the first stage of our project.
*
* In this current version, we can use both the up and down
* keys to trigger the wolf's movements as well as the camera
* using ComputerVision theories to trigger jumping. [UP to 
* jump, DOWN to start]. 
*
* We use the sketch "ComputerVision" to check the supplied 
* video data for colors  below the current thresholding values. 
* When numbers are low than the value, it sends the message
* "Jumping" and through a boolean, the program jumps when it
* recieves it.
*
* Puredata act as background music for this sketch.
*/ 
 
import processing.video.*;
 
Capture video; // video stream
String response; // for response to video
 
PImage[] wolfRun = new PImage[8]; //array with photos of running sprite
PImage[] wolfJump = new PImage[18]; //array with jumping sprite, repeat of three
PImage wolfStand; // stationary wolf
PImage background, obstacle;
 
//booleans to control movement
boolean running = false; boolean jumping = false;
 
//counters
int k = 0; //running
int x = 0; //location 
int m = 0; //jumping
int rand = 400; //location of obstacle
int speed = 10; //location movement
int counter = 0; //increases speed
 
void setup(){
  frameRate(15);
  size(400, 500);
 
  //starts video camera
  video = new Capture(this);
  video.start();
 
  //fills jumping array
  int j = 1;
  int doublej = 0;
  for(int l = 0; l < 18; l++){
    wolfJump[l] = loadImage("WolfJumping" + j + ".png");
    doublej++;
    if(doublej == 3){
      //wants 3 of each photo
      j++;
      doublej=0;
    }
  }
 
  //fills running array
  j = 1;
  for(int i = 0; i < 8; i++){
    wolfRun[i] = loadImage("WolfRunning" + j + ".png");
    j++;
  }
 
  //loads singular photos
  wolfStand = loadImage("WolfStanding1.png");
  background = loadImage("background.png");
  obstacle = loadImage("mossylog.png");
  background.resize(500, 300);
 
}
 
void draw(){
 
  //to show video
  video.read();
  image(video,0,0);
 
  //while running, look to see if the threshhold is present
  if(running == true){
    //stores response each time
    response = ComputerVision(video);
    //checks to see if response is met
    if(response == "Jumping"){
      jumping = true;
    } 
  }
 
  //shows images
  image(background, x, 200);
  image(background, 500 + x, 200);
  image(obstacle, rand + x, 400);
 
  //points or score
  text(counter, 380, 250);
 
 
  //changing of photos to simulate movement
  if (running == false && jumping == false){
  //no movement
  image(wolfStand, 0, 315);
  } else if (running == true && jumping == false){
    //running
    image(wolfRun[k], 0, 315);
    k++;
    if(k == 7){
      //returns to first photo
      k = 0;
    }
    x-=speed;
  } else if(running == true && jumping == true){
    //jumping
    if(m<9){
      //up
      image(wolfJump[m], 0, 315 -(10*m));
    } else if (m<18){
      //down
      image(wolfJump[m], 0, 315 -(10*(17-m)));
    }
    m++;
    if(m == 18){
      //ends jumping
      jumping = false;
      m = 0;
    }
    x-=speed;
  }  
 
  if( (jumping == false) && (rand + x <=80 && (rand+64) +x >=10)){
    //stops wolf and resets when hits obstacle
    running = false;
    speed= 10;
    counter= 0;
  }
 
  if( x < (-500)){
    x=0;
    counter++;
    if(counter%4 == 0){
      speed++;
 
    }
  }
}
 
void keyPressed(){
  if(key == CODED){
    if(keyCode == DOWN){
    running = true;
    } else if (keyCode == UP){
    jumping = true;
    }
  }
}

file: ComputerVision

/* Cassidy Gibson and Daniel Molder 
*
* This sketch uses a video stream and the Pixels array 
* supplied by Processing, to search the array for red values
* below the threshold value. 
*
* If it finds the threshold value, it returns the message
* "Jumping" and when it does not, it returns the message
* "Running".
*/
 
String ComputerVision(Capture cam){
  cam.loadPixels(); // gets pixels
 
  boolean jump = false; // starts boolean
 
  //threshold value
  int threshold = 100;
 
  //different responses that can be sent
  String jumping = "Jumping";
  String running = "Running";
 
  for(int i = 0; i < cam.pixels.length; i++){
    color c = cam.pixels[i]; // gets color
    float r  = red(c); // gets red
 
    //thresholds the red value for when to jummp
    if( r < threshold){
      //if less than the threshold, jumps
      jump = true;
    } else {
      //else continues to run
      jump = false;
    }
  }
 
  if(jump == true){
    return jumping;
  } else {
    return running;
  }
}

pure data file:

photo used for background:

photo used for obstacle:

photos used for jumping animation:

photos used for running animation

photos used for standing:

cs276/a16/cl_dm_p2.txt · Last modified: 2016/12/20 13:36 by ursiidae