///////////////////////////////////
//Click City to change city lights
//Move mouse to direct Robot's spotlight
//Click Robot to blow up building
//CTRL+Click to restart
////////////////////////////////////
///////////////////////////////////
//Leon Hong
//Dec 4, 04
//Proj 4
//Interactive Illustration
///////////////////////////////////////
House city;
Robot joe;
Cars car;
Cars car2d;
Cars car3d;
PImage bg0 = loadImage("bg0.jpg");
PImage bg1 = loadImage("bg1.jpg");
PImage bg2 = loadImage("bg2.jpg");
PImage robot = loadImage("robot.jpg");
PImage robotalpha = loadImage("robotalpha.jpg");
PImage fire2 = loadImage("fire2.jpg");
PImage fire2alpha = loadImage("fire2alpha.jpg");
PImage fire = loadImage("fire.jpg");
PImage firealpha = loadImage("firealpha.jpg");
PImage spotlight = loadImage("spotlight.jpg");
PImage spotlightalpha = loadImage("spotlightalpha.jpg");
PImage light1alpha = loadImage("light1alpha.jpg");
PImage car1 = loadImage("car1.jpg");
PImage car1alpha = loadImage("car1alpha.jpg");
PImage car2 = loadImage("car2.jpg");
PImage car2alpha = loadImage("car2alpha.jpg");
PImage car3 = loadImage("car3.jpg");
PImage car3alpha = loadImage("car3alpha.jpg");
void setup(){
cursor(CROSS);
size (600,300);
framerate(60);
background (0);
city = new House();
joe = new Robot();
car = new Cars(0);
car2d = new Cars(random(50,200));
car3d = new Cars(random(20,100));
alpha(robot,robotalpha);
alpha(fire,firealpha);
alpha(fire2,fire2alpha);
alpha(light1alpha,light1alpha);
alpha(car1,car1alpha);
alpha(car2,car2alpha);
alpha(car3,car3alpha);
angleMode(DEGREES);
}
int test1=0;
void draw(){
car.update();
car2d.update();
car3d.update();
if(test1==2){
city.display();
city.fire();
car.car1();
car.car2();
car.car3();
car2d.car1();
car2d.car2();
car2d.car3();
car3d.car1();
car3d.car2();
car3d.car3();
joe.display();
if(mousePressed==true && keyPressed == true){
test1=0;
car = new Cars(0);
car2d = new Cars(random(50,200));
car3d = new Cars(random(20,100));
}
joe.robotview();
}
else{
if(joe.check(mouseX, mouseY)==false && test1==0){
city.display();
joe.updatealpha();
car.car1();
car.car2();
car.car3();
joe.display();
tint(255,251,209,random(200,255));
image(light1alpha,0,0);
tint(255,255);
}
else{
test1=2;
}
}
interpolate();
}
float mx=600;
float my=300;
float delay = 2.0;
void interpolate()
{
float diffx = mouseX-mx;
if(abs(diffx) > 1) {
mx = mx + diffx/delay;
}
float diffy = mouseY-my;
if(abs(diffy) > 1) {
my = my + diffy/delay;
}
}
class Cars
{
float x=0, y=0;
float x1,y1;
float x2,y2;
float x3,y3;
float mousep=0;
float posxi1;
float posyi1;
float posxi2;
float posyi2;
float posxi3;
float posyi3;
Cars(float offset){
posxi1= 0+random(-10,10)+offset;
posyi1= 0-random(-10,10)+offset;
posxi2= 150+random(-10,10)+offset;
posyi2= 300+random(-10,10)+offset;
posxi3= 600+random(-10,10)+offset;
posyi3= 0-random(-10,10)+offset;
}
void update(){
x++;
y++;
if(y>150){
y=0;
x=0;
}
}
void car1(){
x1=(x*6+posyi1);
y1=(y*3+posxi1);
image(car1,x1,y1);
}
void car2(){
x2=(-x*-.5+posxi2);
y2=(y*-3+posyi2);
image(car2,x2,y2);
}
void car3(){
x3=(x*-.5+posxi3);
y3=(y*3+posyi3);
image(car3,x3,y3);
}
}
class House
{
float x, y;
float mousep=2;
House(){
}
void fire(){
tint(255,random(120,255));
image(fire2,0,0);
tint(255,random(200,255));
image(fire,0,0);
random(150,255);
}
void display(){
if (mousePressed==true){
mousep++;
}
if(mousep==0){
image(bg0,0,0);
}
if(mousep==1){
image(bg1,0,0);
}
else if(mousep==2){
image(bg2,0,0);
}
if (mousep==3){
mousep=0;
}
}
}
PImage spotlightalphaCrop;
class Robot
{
color robocolo;
float value;
boolean [] alphacheckers;
int opac;
float x2, y2;
Robot(){
alphacheckers = new boolean [59100];
for(int i=0; i<173*300; i++) {
robocolo = robotalpha.pixels[i];
value = blue(robocolo);
if(value >5){
alphacheckers[i]=true;
}
else{
alphacheckers[i]=false;
}
}
opac=0;
}
void robotview(){
fill(255,255-opac);
rect(-1,-1,601,301);
opac+=5;
}
void display(){
image(robot,0,0);
}
boolean check(float mx, float my){
if (mousePressed==true && mx<173){
return true;
}
return false;
}
void updatealpha(){
x2=constrain(600-mx,0,300);
y2=constrain(300-my,0,300);
spotlightalphaCrop = spotlightalpha.get(int(x2),int(y2), 600, 300);
alpha(spotlight,spotlightalphaCrop);
image(spotlight,0,0);
opac=0;
}
}