Fade out

edited March 2016 in How To...

I have made a short story with 4 scenes. To finish, i need to fade out the last scene but when I try this, scene 4 begins with a black rectangle that fades. I can't find where to change the opacity for it to begin with it not even being there. Also, for some odd reason, the turtle is moved on scene 4 despite having the same coordinates and then after fading out, it begins a new scene

PImage img;                    // Declare variable "img" of type PImage
float moveBoat;
float speedBoat;
float moveTurtle;
float speedTurtle;
float moveSeagull;
float speedSeagull;
float moveDog;
float speedDog;
float moveCrab;
float speedCrab;
float moveBoat2;
float speedBoat2;
int time;
int time2;

void setup() {
  fullScreen();                          // use fullScreen() instead of size()
  background( 0 );
  img = loadImage("http://eskipaper.com/images/beach-background-4.jpg");     // Load the image into the program
  imageMode( CENTER );                   // position the center, not upper right, of the image
  colorMode(HSB, 100);                        // hue, sat, brightness color system

  moveBoat = 0;
  speedBoat = 1;

  moveTurtle = 0;
  speedTurtle = 1;

  moveSeagull = 0;
  speedSeagull = 1;

  moveBoat2 = 0;
  speedBoat2 = 1;

  moveCrab = 0;
  speedCrab = 1;

}

void draw() {

  //background( 0 );d
  time = millis() % 40000;
  time2 = millis() % 17000;

    if  (time < 15500 ) {              // SCENE 1
    scene1();

     } 

    if  (time > 15500 && time < 23000 ) {              // SCENE 2
    scene2();
    }

    if  (time > 23000 && time < 33000 ) {              // SCENE 3
    scene3();
    }

    if  (time > 33000 && time < 40000 ) {              // SCENE 4
    scene4();
    }

}

void scene1()
{
  tint(0, 0, 360, 255);                             // Display full opacity no color tint
  image(img, width/2, height/2);                    // Display at full opacity

 pushMatrix();
 //translate( -100, 0 );
 if(moveBoat < 2000)
 {
   speedBoat = speedBoat + 2;
   moveBoat++;
 translate(speedBoat,0);
  Boat();

 }
  popMatrix();

   pushMatrix();
 //translate( -100, 0 );
 if(moveCrab < 300)
 {
   speedCrab = speedCrab + 1;
   moveCrab++;
 translate(speedCrab,0);
  Crab();

 }
 else
 {
   translate(300,0);
   Crab();
 }

  popMatrix();

  fill( 0, 0, 0, ( 360.0 * ( (5500.0 - time)/15500.0 )));
  //fill(100);
  noStroke();
  rect( 0, 0, width, height );
}

void scene2()
{
  tint(0, 0, 360, 255);                             // Display full opacity no color tint
  image(img, width/2, height/2);                    // Display at full opacity

   translate(300,0);
   Crab();

 pushMatrix();
 //translate( -100, 0 );
 if(moveTurtle < 350)
 {
   speedTurtle = speedTurtle + 1;
   moveTurtle++;
 translate(speedTurtle,0);
  Turtle();
 }
  else
 {
   translate(350,0);
   Turtle();
 }
 popMatrix();
 }

 void scene3()
{
  tint(0, 0, 360, 255);                             // Display full opacity no color tint
  image(img, width/2, height/2);                    // Display at full opacity

  translate(300,0);
  Crab();
  translate(350,0);
  Turtle();

 pushMatrix();
 //translate( -100, 0 );
 if(moveBoat2 < 2000)
 {
   speedBoat2 = speedBoat2 + 3;
   moveBoat++;
 translate(-speedBoat2,0);
  Boat2();

 }
  popMatrix();

   pushMatrix();
 //translate( -100, 0 );
 if(moveSeagull < 2000)
 {
   speedSeagull = speedSeagull + 3;
   moveSeagull++;
 translate(speedSeagull,0);
  Seagull();

 }
  popMatrix();
}

 void scene4()
{
  tint(0, 0, 360, 255);                             // Display full opacity no color tint
  image(img, width/2, height/2);                    // Display at full opacity

  pushMatrix();
  translate(300,0);
  Crab();
  popMatrix();

  pushMatrix();
  translate(350,0);
  Turtle();
  popMatrix();

 pushMatrix();
 translate(0,200);
 if(moveDog < 200)
 {
   speedDog = speedDog + 1;
   moveDog++;
 translate(0,-speedDog);
  Dog();
 }

  else { 
   translate(0,400);
   Dog(); 
 }
 popMatrix();

  fill( 0, 0, 0, ( 360 * ( (0 + time2)/40000.0 )));
  noStroke();
  rect( 0, 0, width, height );
}

void Turtle() { 
  noFill();
  stroke(33, 86, 32);
  strokeWeight(8);
  strokeCap(ROUND);
  strokeJoin(ROUND);
  line(0, 800, 50, 770 );                          //Create right top fin
  noFill();
  stroke(33, 86, 32);
  strokeWeight(8);
  strokeCap(ROUND);
  strokeJoin(ROUND);
  line(0, 800, 50, 830 );                          //Create right bottom fin
  noFill();
  stroke(33, 86, 32);
  strokeWeight(8);
  strokeCap(ROUND);
  strokeJoin(ROUND);
  line(-5, 800, -50, 770 );                          //Create left top fin
  noFill();
  stroke(33, 86, 32);
  strokeWeight(8);
  strokeCap(ROUND);
  strokeJoin(ROUND);
  line(-5, 800, -50, 830 );                          //Create left bottom fin
  fill(10, 86, 32);
  noStroke();
  ellipse(0, 800, 80, 60);                          //Create brown shell
  fill(33, 86, 32);
  noStroke();
  ellipse(50, 800, 40, 30);                          //Create head
  ellipseMode(RADIUS);
  noStroke();
  fill(100);
  ellipse(50, 807, 3, 3);
  ellipseMode(CENTER);
  stroke(0);
  strokeWeight(2);
  fill(100);
  ellipse(50, 807, 2, 2);                              //Create bottom eye
  ellipseMode(RADIUS);
  noStroke();
  fill(100);                                 
  ellipse(50, 793, 3, 3);
  ellipseMode(CENTER);  
  stroke(0);
  strokeWeight(2);
  fill(100);
  ellipse(50, 793, 2, 2);                              //Create top eye
}

void Boat () {
 noStroke();
 fill(70, 50, 80);
 bezier(300, 630, 380, 675, 410, 675, 490, 630);        //Hull
 stroke(0);
 strokeWeight(2);
 fill(100);
 ellipse(370, 645, 8, 8);                               //Create left window
 stroke(0);
 strokeWeight(2);
 fill(100);
 ellipse(395, 645, 8, 8);                               //Create center window
 stroke(0);
 strokeWeight(2);
 fill(100);
 ellipse(420, 645, 8, 8);                               //Create right window
 stroke(0);
 strokeWeight(6);
 line(395, 630, 395, 500);                              //Pole
 noStroke();
 fill(100);
 triangle(400, 540, 400, 500, 455, 520);                //Flag
}

 void Crab () 
 {
  stroke(0);
  strokeWeight(3);
  strokeCap(ROUND);
  strokeJoin(ROUND);
  line(460, 800, 450, 830 );                          //Create outter left leg
  stroke(0);
  strokeWeight(3);
  strokeCap(ROUND);
  strokeJoin(ROUND);
  line(470, 800, 460, 830 );                          //Create middle left leg
  stroke(0);
  strokeWeight(3);
  strokeCap(ROUND);
  strokeJoin(ROUND);
  line(480, 800, 470, 830 );                          //Create inner left  leg
  stroke(0);
  strokeWeight(3);
  strokeCap(ROUND);
  strokeJoin(ROUND);
  line(540, 800, 550, 830 );                          //Create outter right  leg
  stroke(0);
  strokeWeight(3);
  strokeCap(ROUND);
  strokeJoin(ROUND);
  line(530, 800, 540, 830 );                          //Create middle right leg
  stroke(0);
  strokeWeight(3);
  strokeCap(ROUND);
  strokeJoin(ROUND);
  line(520, 800, 530, 830 );                          //Create inner right  leg
  fill(0, 100 , 100);
  noStroke();
  ellipse(500, 800, 100, 60);                          //Create red body
  noFill();
  stroke(359, 100, 0);
  strokeWeight(6);
  strokeCap(SQUARE);
  strokeJoin(ROUND);
  bezier(470, 800,  440, 785,  440, 770, 470, 755);      //Create left arm
  fill(0, 100 , 100);
  noStroke();
  ellipse(470, 755, 20, 20);                               //Create left claw
  noFill();
  stroke(359, 100, 0);
  strokeWeight(6);
  strokeCap(SQUARE);
  strokeJoin(ROUND);
  bezier(530, 800,  560, 785,  560, 770, 530, 755);      //Create right arm
  fill(0, 100 , 100);
  noStroke();
  ellipse(530, 755, 20, 20);                               //Create left claw
  ellipseMode(RADIUS);
  noStroke();
  fill(100);
  ellipse(480, 800, 3, 3);
  ellipseMode(CENTER);
  stroke(0);
  strokeWeight(2);
  fill(100);
  ellipse(480, 800, 1, 1);                              //Create left eye
  ellipseMode(RADIUS);
  noStroke();
  fill(100);                                 
  ellipse(520, 800, 3, 3);
  ellipseMode(CENTER); 
  stroke(0);
  fill(100);
  ellipse(520, 800, 1, 1);                              //Create right eye
 }  
void Boat2 ()
{
 noStroke();
 fill(30, 80, 100);
 bezier(800, 630, 880, 675, 910, 675, 990, 630);        //Hull
 stroke(0);
 strokeWeight(2);
 fill(100);
 ellipse(870, 645, 8, 8);                               //Create left window
 stroke(0);
 strokeWeight(2);
 fill(100);
 ellipse(895, 645, 8, 8);                               //Create center window
 stroke(0);
 strokeWeight(2);
 fill(100);
 ellipse(920, 645, 8, 8);                               //Create right window
 stroke(0);
 strokeWeight(6);
 line(895, 630, 895, 500);                              //Pole
 noStroke();
 fill(100);
 triangle(900, 540, 900, 500, 955, 520);                //Flag
}

 void Seagull()
 {
 noFill();
 strokeCap(ROUND);
 stroke(0);
 strokeWeight(8);
 line(0, 90, -20, 80);                            //Create top wing
 noStroke();
 fill(100);
 ellipse(0, 100, 50, 30);                            //Create body
 noStroke();
 fill(100);
 ellipse(30, 100, 25, 25);                            //Create head
 noFill();
 strokeCap(ROUND);
 stroke(10, 80, 100);
 line(38, 103, 55, 103);                             //Create beak
 noFill();
 strokeCap(ROUND);
 stroke(0);
 strokeWeight(8);
 line(0, 110, -20, 120);                            //Create bottom wing
 stroke(0);
 strokeWeight(2);
 fill(100);
 ellipse(30, 100, 1, 1);                              //Create eye
 }

 void Dog()
 {
 fill(10, 86, 50);
 noStroke();
 ellipse(1000, 800, 175, 225);                          //Create brown head
 fill(0);
 stroke(0);
 strokeWeight(8);
 strokeJoin(ROUND);
 triangle(1000, 875, 970, 835, 1030, 835);              //Create nose
 ellipseMode(RADIUS);
 noStroke();
 fill(100);
 ellipse(975, 775, 15, 20);
 ellipseMode(CENTER);
 stroke(0);
 strokeWeight(2);
 fill(0);
 ellipse(975, 775, 10, 20);                              //Create left eye
 ellipseMode(RADIUS);
 noStroke();
 fill(100);
 ellipse(1025, 775, 15, 20);
 ellipseMode(CENTER);
 stroke(0);
 strokeWeight(2);
 fill(0);
 ellipse(1025, 775, 10, 20);                              //Create right eye
 fill(10, 86, 70);
 stroke(10, 86, 70);
 strokeWeight(8);
 strokeJoin(ROUND);
 triangle(1040, 695, 1092, 830, 1100, 768);              //Create right ear
 fill(10, 86, 70);
 stroke(10, 86, 70);
 strokeWeight(8);
 strokeJoin(ROUND);
 triangle(960, 695, 908, 830, 900, 768);              //Create left ear

}
Sign In or Register to comment.