//The Dream
//by Scott Yacyshyn
//click to continue the story

int frame = 0;
int numFrames = 7;
int fram = 0;

PImage[] images = new PImage[ numFrames];
PImage ouch;
PImage look;
PImage whoa;
PImage see;
PImage fly;
PImage whelm;
PImage wake;
PImage shok;
PImage awe;

float maxShake;
float xpos;
float ypos;
float apos = 0;
float angle = 0.0;
float speed = 3;
float sinval = sin(angle);
float cosval = cos(angle);
float mx;
float my;
float delay = 10.0;
float dx;
float dy;

void setup() {
size(600, 300);
images[ 0] = loadImage("frame1.jpg");
images[ 1] = loadImage("frame2.jpg");
images[ 2] = loadImage("frame3.jpg");
images[ 3] = loadImage("frame4.jpg");
images[ 4] = loadImage("frame5.jpg");
images[ 5] = loadImage("frame6.jpg");
images[ 6] = loadImage("frame7.jpg");
ouch = loadImage("hithard.gif");
look = loadImage("stand.jpg");
whoa = loadImage("see.gif");
see = loadImage("look.jpg");
fly = loadImage("fly.gif");
whelm = loadImage("cliff.gif");
wake = loadImage("wakeup.jpg");
shok = loadImage("wakeup2.jpg");
awe = loadImage("wakeup3.jpg");
}

void draw() {
background(255);
framerate(10);
if(frame == 0) {
  fall();
} else if(frame == 1) {
  hit();
} else if(frame == 2) {
  still();
} else if(frame == 3) {
  wow();
} else if(frame == 4) {
  guh();
} else if(frame == 5) {
  overwhelm();
} else if(frame == 6) {
  wakem();
} else if(frame == 7) {
  shock();
} else if(frame == 8) {
  relief();
}
}

void fall() {
strokeWeight(1.75);
maxShake = 1;
xpos = 0 + random(2*maxShake)-maxShake;
ypos = 0;
line(xpos + 100, 20, xpos + 100, 230);
line(xpos + 410, 30, xpos + 410, 260);
line(xpos + 50, 0, xpos + 50, 40);
line(xpos + 130, 250, xpos + 130, 300);
line(xpos + 500, 120, xpos + 500, 300);
line(xpos + 550, 70, xpos + 550, 200);
image(images[ fram], 150, 10);
fram = (fram+1)%numFrames;

}

void hit() {
framerate(60);
maxShake = 3;
xpos = 0 + random(2*maxShake)-maxShake;
ypos = 0;
image(ouch, xpos, ypos);
}

void still() {
image(look, 0, 0);
}

void wow() {
background(40);
framerate(60);
fill(255);

angle = angle + speed;
sinval = sin(angle*2.0);
cosval = cos(angle*2.0);
ellipse(100+(cosval*30), 100+(sinval*30), 10, 10);
ellipse(400+(cosval*25), 190+(sinval*25), 10, 10);
ellipse(200+(cosval*30), 160+(sinval*35), 10, 10);
ellipse(500+(sinval*05), 20+(cosval*05), 10, 10);
ellipse(50+(cosval*60), 130+(sinval*30), 20, 20);
ellipse(150 +(sinval* -60), 80+(cosval*50), 15, 15);
ellipse(300 + (sinval* 40), 50+(cosval*40), 14, 14);
ellipse(mouseX + (cosval*100), mouseY + (sinval*30), 10, 10);
ellipse(mouseX + (cosval*90), mouseY + (sinval*50), 10, 10);
ellipse(mouseX + (sinval*60), mouseY + (cosval*10), 15, 15);
ellipse(mouseY + (sinval*120), mouseX + (cosval*70), 15, 15);
ellipse(mouseY + (cosval*50), mouseX + (sinval*25), 10, 10);
image(whoa, 0, 0);
fill(51, 10);
noStroke();
rect(0, 0, width, height);
}

void guh() {
smooth();
image(see, 0, 0);
fill(40);
if(abs(mouseX - mx) > 0.1) {
  mx = mx + (mouseX - mx)/delay;
  }
if(abs(mouseY - my) > 0.1) {
  my = my + (mouseY - my)/delay;
  }
if(abs(mouseY - dy) > 0.1) {
  dy = dy + (mouseY - dy)/delay;
  }
if(abs(mouseX - dx) > 0.1) {
  dx = dx + (mouseX - dx)/delay;
  }
mx = constrain(mx, 300, 600);
dx = constrain(dx, 175, 215);
dy = constrain(dy, 150, 180);
ellipse(dx, dy, 20, 35);
fill(255);
ellipse(dx-10, dy-10, 15, 15);
image(fly, mx, my);
}

void overwhelm() {
framerate(60);
background(30);
  mx = mouseX;
  fill(255);
  noStroke();
apos = apos + 1;
if(apos > width) {
  apos = 0;
}
drawdog(150, 180, 100);
drawdog(30, 20, 50);
drawdog(200, 60, 150);
drawdog(100, 100, 80);
drawdog(250, 220, 40);
drawdog(60, 230, 120);
drawdog(10, 150, 60);
drawdog(170, 285, 190);
drawdog(250, 150, 100);
drawdog(300, 100, 80);
drawdog(340, 200, 200);
drawdog(400, 50, 80);
drawdog(560, 180, 120);
drawdog(470, 150, 60);
drawdog(apos, 50, 50);
drawdog(apos/2, 200, 110);
drawdog(apos, 110, 30);
drawdog(apos*2, 80, 90);
drawdog(apos*6, 30, 140);
drawdog(apos*10, 260, 190);
image(whelm, 0, 0);
}

void wakem() {
angle = angle + speed;
cosval = cos(angle*2.0);
maxShake = 2;
xpos = 0+(cosval*30);
ypos = 0;
fill(217, 217, 217);
rect(0, 0, width, height);
image(wake, xpos, ypos);
}

void shock() {
image(shok, 0, 0);
}

void relief() {
background(40);
fill(100);
angle = angle + speed;
sinval = sin(angle*2.0);
cosval = cos(angle*2.0);
image(awe, 0, 0);
ellipse(mouseX+(cosval*80), mouseY+(sinval*60), 10, 10);
}




void drawdog(float xpos, float ypos, float scaleval) {
push();
translate(xpos, ypos);
scale(scaleval, scaleval);
beginShape(POLYGON);
  vertex(.4, -.2);
  vertex(.4, -.05);
  vertex(.35, -.1);
  vertex(.35, -.05);
  vertex(.3, -.1);
  vertex(.3, -.05);
  vertex(.25, -.1);
  vertex(.2, 0);
  vertex(.25, .05);
  vertex(.3, 0);
  vertex(.3, .05);
  vertex(.35, 0);
  vertex(.35, .05);
  vertex(.4, 0);
  vertex(.4, .1);
  vertex(.15, .1);
  vertex(.15, .2);
  //vertex(.2, .25);
  vertex(.15, .2);
  vertex(.2, .25);
  vertex(.15, .25);
  vertex(.2, .3);
  vertex(.05, .3);
  vertex(.05, .1);
  vertex(-.1, .1);
  vertex(-.1, .2);
  vertex(-.05, .25);
  vertex(-.1, .25);
  vertex(-.05, .3);
  vertex(-.2, .3);
  vertex(-.2, 0);
  vertex(-.35, 0);
  vertex(-.4, -.15);
  vertex(-.3, -.05);
  vertex(-.2, -.05);
  vertex(-.1, -.15);
  vertex(.05, -.15);
  vertex(.05, -.25);
  vertex(.1, -.2);
  vertex(.1, -.25);
  vertex(.15, -.2);
endShape();
pop();
}


void mousePressed() {
frame = frame + 1;
println(frame);
}
Project 4: Context
Extend an idea you've explored previously in your life, but adapt it to the context of an interactive system which requires the viewer to engage with the material.