Interactive Authoring- Final

 

Code:

import processing.video.*;
import gab.opencv.*;
import java.awt.Rectangle;
PImage src;
PImage Heart;
PImage Fear;
PImage skull;
PImage Death;
boolean love = false;
boolean love2 = false;
boolean love3 = false;
float mouseVelocity;
float ploc;
float Parallax;
int window = 0;
boolean Scroll;
boolean debug = true;
int Fearful;
int video = 1;
int i;
int[] windowloc;

Capture cam;
OpenCV opencv;
Movie dating;
Movie Love;
Movie Luve;
Movie Dan;
Rectangle[] faces;

void setup () {
size (640, 480);
surface.setResizable (false);
String[] cameras = Capture.list();
cam = new Capture(this, 640, 480, cameras[0]);
cam.start();
src = cam;
opencv = new OpenCV(this, src);
opencv.loadCascade (OpenCV.CASCADE_FRONTALFACE);
Heart = loadImage (“Heart.png”);
Fear = loadImage (“Fear.png”);
Death = loadImage (“Death.png”);
skull= loadImage (“Skull.png”);
dating = new Movie(this, “Love 1.mov”);
Love = new Movie (this, “Love 2.mov”);
Luve = new Movie (this, “Love 8.mov”);

windowloc = new int [5];
windowloc [0] = 0;
windowloc [1] = 640;
windowloc [2] = 1280;
windowloc [3] = 1920;
windowloc [4] = 2560;
}
void draw () {
image (cam, 0+Parallax, 0);
background (0);
faces = opencv.detect();
if (Scroll){
if (Parallax != windowloc[window]){
lerp (Parallax, windowloc[window], .01);
//look up lerp()
//look up easing
}else { Scroll = false;
}
}
if (keyPressed == true) {
love = true;
}
if (keyPressed == true && Parallax == -640) {
love2 = true;
}
if (keyPressed == true && Parallax == -640) {
love3 = true;
}
//if (Parallax > 0*(window)) {
//rScroll = false;
// window = 1;
// }
// if (Parallax < -640*(window-1)) {
//lScroll = false;
// window += 1;
// }

//if (Scroll) {
// Parallax += 4;
//Parallax -= 4;

//if (getCursorVelocity() > 50) {
//rScroll = true;
if (getCursorVelocity() < -50 || getCursorVelocity() > 50 ) {
Scroll = true;
}
if (love == true && window == windowloc[0] && video == 1 && Scroll) {
Parallax = -640;
}
if (love2 == true && Scroll == true && video == 2) {
Parallax = -1280;
}
if (love3 == true && Scroll == true && video == 3) {
Parallax = -2560;
}

opencv.loadImage(src);
cam.loadPixels();
image (dating, 0+Parallax, 0);
image (Love, 640+Parallax, 0);
image (Luve, 640+Parallax, 0);
PVector loc = opencv.max();

if (love == true && mouseX >= 620 && mouseY >= 440) {
dating.play();
video = 1;
}
if (love2 == true) {
Love.play();
video = 2;
}
if (love3 == true && mouseX >= 620 && mouseY >= 440) {
Luve.play();
video = 3;
}
if (window == 1) {
if (window == 2 && getCursorVelocity() < -50) {
window = 3;
}
love = true;
video = 1;
Scroll= true;
}
else if (window == 2) {
if (window == 3 && getCursorVelocity() < -50) {
window = 4;
}
love3 = true;
video = 3;
love2 = true;
video = 2;
Scroll= true;
}
else if (window == 3) {
if (window == 4 && getCursorVelocity() < -50) {
window = 3;
}

Scroll= true;
}
else if (window == 4) {
if (window == 2 && getCursorVelocity() < -50) {
window = 3;
}

Scroll= true;
}
if (love == true && window == windowloc[0] && video == 1 && Scroll) {
Parallax = -640;
}
if (love2 == true && Scroll == true && video == 2) {
Parallax = -1280;
}
if (love3 == true && window == windowloc[3] && Scroll == true && video == 3) {
Parallax = -2560;
}

fill (255);
stroke (255);
rect ((0) + (2560 + Parallax), 0, 640, 480);

if (!debug) {
stroke(255, 0, 0);
strokeWeight(4);
noFill();
ellipse(loc.x, loc.y, 10, 10);
if (loc.x >= 620 && loc.y >= 440) {
image(Heart, -23+Parallax, 249);
}
} else {
//debug mode
stroke(255, 0, 0);
strokeWeight(4);
noFill();
ellipse(mouseX, mouseY, 10, 10);
if (mouseX >= 620 && mouseY >= 440) {
image(Heart, -23+Parallax, 249);
}
if (mouseX >= 620 && mouseY >= 440) {
image(Fear, 427+Parallax, -232);
} if (mouseX >= 620 && mouseY >= 440) {
image(Death, 2560+Parallax, -232);
}
if (keyPressed == true) {
love = true;
}
}
if (Parallax == -2560 && keyPressed == true) {
image (cam, 2560+Parallax, 0);
image (skull, faces[i].x-120, faces[i].y-170, faces[i].width*2, faces[i].height*3);
}
println (Parallax);
if (Scroll) {
println (“Scrolling”);
}

ploc=loc.x;
}
float getCursorVelocity () {
PVector loc = opencv.max();
float v = loc.x-ploc;
if (debug) {
v = mouseX-pmouseX;
}
return v;
}
void movieEvent(Movie m) {
m.read();
}
void captureEvent (Capture cam) {
cam.read();
}

Advertisements
This entry was posted in Time-Based and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s