Tint carries on to next function?

edited November 2017 in Questions about Code
PImage[] walkcycle = new PImage[8];
PImage[] walkcycle1 = new PImage[8];
PImage mandrell;
float x = 0;
float y = 0;
float z = 0;
float c = 0;
float v = 380;
float g = 500;
int walkPics = 0;
  int number = 0;


void setup() {
  size(500, 600);
    walkcycle[0] = loadImage("1.png");
  walkcycle[1] = loadImage("2.png");
  walkcycle[2] = loadImage("3.png");
  walkcycle[3] = loadImage("4.png");
  walkcycle[4] = loadImage("5.png");
  walkcycle[5] = loadImage("6.png");
  walkcycle[6] = loadImage("7.png");
  walkcycle[7] = loadImage("8.png"); 
 mandrell = loadImage("mandrill.jpg");
  mainMenu();
}

void draw() {
  if (key == '1') {
    fourWalkers();
  }
}

void keyPressed() {
  if (key == '0') {
    mainMenu();
  }
 else if (key == '1') {
    fourWalkers();
  }
  else if (key == '2') {
    mainMandrell();
  }
}


void mainMenu() {
  fill(255);
  strokeWeight(2);
  rect(0, 0, width, 480);
  rect(0, 480, width, 120);
  textSize(25);
  fill(1);
 textSize(15);
 number = 0;
  text("Main Menu", 200, 50);
  text("0 - Main Menu", 150, 200);
  text("1 - Four Walkers", 150, 230);
  text("2 - Mandrill", 150, 260);
  text("3 - Love", 150, 290);
    text("Last Key Pressed:" + number, 350, 550);
}



void fourWalkers() {
  background(255);
 fill(150);
  rect(0, 0, width, 480);

  noTint();
  image(walkcycle[walkPics], x, y, 58.9, 100);
    x+= 7;
  y+= 5;
  walkPics++;
  if (walkPics >= walkcycle.length) {
    walkPics = 0;
  }
  if (x > width) {
    x = 0;
    y = 0;
  }

  tint(255, 0, 0);
   image(walkcycle[walkPics], z, 180, 58.9, 100);
   z += 7;
  walkPics++;
  if (walkPics >= walkcycle.length) {
    walkPics = 0;
    if (z > 500) {
      z = 0;
    }
  }

    tint(0, 0, 255);
   image(walkcycle[walkPics], c, v, 58.9, 100);
   c += 7;
   v -= 5;
  walkPics++;
  if (walkPics >= walkcycle.length) {
    walkPics = 0;
  }
      if (c > width) {
     c = 0;
     v = 380;
      }
          tint(0, 255, 0);
   image(walkcycle[walkPics], g, 180, 58.9, 100);
   g -= 7;
  walkPics++;
  if (walkPics >= walkcycle.length) {
    walkPics = 0;
    if (g < 0) {
      g = 500;
    }
  }
  number = 1;
  textSize(15);
  fill(1);
  text("Man Original Height: 158.0", 10, 510);
  text("Man Original Width: 93.0", 10, 530);
  text("Man New Heigh: 100", 10, 550);
  text("Man New Scaled Width: 58.9", 10, 570);
  text("Last Key Pressed:" + number, 350, 550);
}


void mainMandrell() {
  background(255);
  rect(1, 1, width, height - 120);
  image(mandrell, 1, 1, width, height - 120);
  loadPixels();
  mandrell.loadPixels();
  for (int n = 0; n < mandrell. width; n++) {
    for (int m = 0; m < mandrell.height; m++) {
      int i = n + m * mandrell.width;
      float r = red(mandrell.pixels[i]);
      float g = green(mandrell.pixels[i]);
      float b = blue(mandrell.pixels[i]);
      if (x < 200) {
        pixels[i] = color( g, r, b);
      } else {
        pixels[i] = color(r, g, b);
      }
    }
  }
    mandrell.updatePixels();
}

when I press 1, then 2 the picture of the mandrill is in green tint. I'm trying to tint the mandrill into 1/3rd red, 1/3rd green and 1/3rd blue. Did i make a mistake? thanks!

Answers

Sign In or Register to comment.