Thursday, October 30, 2014

Project 1 Demonstration

Setting up the Jankatron's lightsTesting Jankatron with camera and ProcessingJankatron 1.0The Jankatron keeps jake companyJake programming like a bossIMG_7249

Slides: https://docs.google.com/presentation/d/15bwDZquwddGGuSol8JGsd22IePLhdX324xOZdU0dEjs/edit?usp=sharing

Program code:
// – Super Fast Blur v1.1 by Mario Klingemann <http://incubator.quasimondo.com&gt;
// – BlobDetection library
import processing.video.*;
import blobDetection.*;
Capture cam;
BlobDetection theBlobDetection;
PImage img;
boolean newFrame=false;
ArrayList shapes;
ArrayList shape;
// ==================================================
// setup()
// ==================================================
void setup()
{
// Size of applet
size(640, 480, P2D);
// Capture
cam = new Capture(this, 640/2, 480/2);
// Comment the following line if you use Processing 1.5
cam.start();
// BlobDetection
// img which will be sent to detection (a smaller copy of the cam frame);
img = new PImage(80,60);
theBlobDetection = new BlobDetection(img.width, img.height);
theBlobDetection.setPosDiscrimination(true);
theBlobDetection.setThreshold(0.3f); // will detect bright areas whose luminosity > 0.2f;
shapes = new ArrayList();
}
// ==================================================
// captureEvent()
// ==================================================
void captureEvent(Capture cam)
{
cam.read();
newFrame = true;
}
// ==================================================
// draw()
// ==================================================
void draw()
{
if (newFrame)
{
newFrame=false;
image(cam,0,0,width,height);
img.copy(cam, 0, 0, cam.width, cam.height,
0, 0, img.width, img.height);
//fastblur(img, 2);
theBlobDetection.computeBlobs(img.pixels);
drawShapes();
}
if(shapes.size()>=5hapes.remove(0);
if(shapes.size()>=200
for (int i = 0; i<=5; i++) shapes.remove(i);
}
}
// ==================================================
// drawBlobsAndEdges()
// ==================================================
void drawShapes()
{
Blob b;
EdgeVertex eA,eB;
PShape s;
for (int n=0 ; n{
s = createShape();
s.beginShape();
s.fill(255,0,0);
s.noStroke();
b=theBlobDetection.getBlob(n);
if (b!=null)
{
for (int m=0;m{
eA = b.getEdgeVertexA(m);
if (eA != null)
s.vertex(eA.x*width, eA.y*height);
}
}
s.endShape(CLOSE);
shapes.add(s);
}
for (int o=0; o<shapes.size(); o++){
PShape shape = shapes.get(o);
shape(shape, 0, 0);
}
print(shapes.size(), ” “);
}

Projection Mapping on an Organic Object



photo 2
photo 3photo 1

With Jason Hilgemeier

Interactive Processing Exercise

For this exercise our team made a basic snake game using Processing.  To make the controls interactive, we used Makey-makey with a wooden snake.  The idea was that if you turned the snake right or left, the snake on the screen would also turn right or left.  This interaction didn't work out perfectly, but we did come up with more ideas to make it work better in the future.

As an additional feature, we included sound and color.  The snake begins black, and slowly becomes more colorful as the player acquires more of the "fruits". Additionally, past a certain point, the intro to "Sandstorm" by Darude starts playing on loop.  When the snake reaches complete white color, the snake starts flashing rainbow and Sandstorm plays at full force.  During this time the snake is invincible, and cannot die by running into themselves. The song plays for several seconds, and then stops, with the snake black again.  The process then repeats until the player loses the game.

With Jason Hilegmeier, Nicholas Smith, and Dean Zhu



Processing Code:

import ddf.minim.*;
Minim minim;

sound buildUp;
sound buildUpLoop;
sound drop;
PImage img;

boolean up, down, right, left;
int posX = 0;
int posY = 0;
ArrayList snake;
int time = 0;
int snakeInc = 4;
point fruit = new point(0,0);
int score = 0;
int red = 5;
int green = 5;
int blue = 5;
int backgroundValue = 200;
boolean godMode = false;
boolean start = false;
boolean loop = false;
int timer = 0;

void setup(){
  up = true;
  fruit.x = 0;
  fruit.y = 0;
  moveFruit();
  minim = new Minim(this);
  img = loadImage("Terrbear.jpg");
  buildUp = new sound("loopStart.wav");
  buildUpLoop = new sound("loopContinue.wav");
  drop = new sound("He-man.mp3");
  smooth();
  size(500, 400);
  posX = width/2;
  posY = height/2;
  snake = new ArrayList();
  snake.add(new point(posX, posY));
  snake.add(new point(posX, posY - 5));
  snake.add(new point(posX, posY - 10));
}

void keyPressed(){
 if (keyCode == RIGHT){
  if(up){
   right = true; up = false; left = false; down = false;
  }
  else if(right){
   right = false; up = false; left = false; down = true;
  }
  else if(left){
   right = false; up = true; left = false; down = false;
  }
  else if(down){
   right = false; up = false; left = true; down = false;
  }
 }

 else if (keyCode == LEFT){
  if(down){
   right = true; up = false; left = false; down = false;
  }
  else if(left){
   right = false; up = false; left = false; down = true;
  }
  else if(right){
   right = false; up = true; left = false; down = false;
  }
  else if(up){
   right = false; up = false; left = true; down = false;
  }
 }
}

void moveFruit(){
 fruit.x = 5*(int(random(10, (width - 10)/5)));
 fruit.y = 5*(int(random(10, (height - 10)/5))); 

}

void checkCollide(){
  if ((posX == fruit.x || posX == fruit.x + 5 || posX == fruit.x + 10) && (posY == fruit.y || posY == fruit.y + 5 || posY == fruit.y + 10)){
  snakeInc = 0;
  score +=100;
  red += 30;
  if(backgroundValue > 75) backgroundValue -= 10;
  if(red >= 255) green +=30;
  if(green >= 255) blue +=30;
  moveFruit();
  }
  if(!godMode){
  for(int i = 1; i < snake.size()-1; ++i){
    point point = snake.get(i);
    if (posX == point.x && posY == point.y) { print("Score: ", score); exit();}
  }
  }
  //if(posX == width || posX == 0 || posY == height || posY == 0){ print("Score: ", score); exit();}
  if(posX == width) posX = 5;
  else if(posX == 0) posX = width - 5;
  else if(posY == height) posY = 5;
  else if(posY == 0) posY = height - 5;
}
  

void draw() {
  time++;
  if(time % 1 == 0){
  if(godMode) timer++;
  if(timer > 1000){
    timer = 0;
    godMode = false;
   drop.song.pause();
    red = 5; blue = 5; green = 5;
    backgroundValue = 200;
  }
  checkCollide();
  background(backgroundValue, backgroundValue, backgroundValue); 
  fill(255, 255, 255);
  rect(fruit.x, fruit.y, 15, 15);
    stroke (red, green, blue);
  fill (red, green, blue); 
  
  if(!buildUp.song.isPlaying() && !buildUpLoop.song.isPlaying() && loop == true){
    buildUp.song.rewind();
    buildUpLoop.song.loop();
  }
  
  if(blue >= 150 && !buildUp.song.isPlaying() && !buildUpLoop.song.isPlaying()) {
    buildUp.song.play();
    loop = true;
  }

  
   if(red >=255 && green >= 255 && blue >=255) {
    godMode = true;
    buildUpLoop.song.pause();
    buildUpLoop.song.rewind();
    drop.song.play();
    image(img, random(0, width), random(0, height));
    int r = int(random(0,255));
    int g = int(random(0,255));
    int b = int(random(0, 255));
    stroke(r, g, b);
    fill(r, g, b);
  }


  if(up){
    posY -= 5;
    snake.add(new point(posX, posY));
    if(snakeInc < 3) snakeInc++;
    else{ snake.remove(0);}
  }
  
  if(right){
    posX += 5;
    snake.add(new point(posX, posY));
    if(snakeInc < 3) snakeInc++;
    else{ snake.remove(0);}
  }
  
  if(down){
    posY += 5;
    snake.add(new point(posX, posY));
    if(snakeInc < 3) snakeInc++;
    else{ snake.remove(0);}
  }
  
  if(left){
    posX -= 5;
    snake.add(new point(posX, posY));
    if(snakeInc < 3) snakeInc++;
    else{ snake.remove(0);}
  }
  for(int i = 0; i
    point point = snake.get(i);
    rect(point.x, point.y, 5, 5);
  }
  }
}

class sound {
   AudioSnippet song;
   sound (String filename) {
    // load "dingdong.wav" into a new AudioPlayer
    song = minim.loadSnippet(filename);
  }
}

class point{
  point(int tempx, int tempy){x = tempx; y = tempy;}
  int x;
  int y;
}