Help with Painting Program

When I use the save function it changes the background to red and erases what is painted, Wondering how I can save without it going away and background staying orange. Also need help with creating a way to have the other paint buckets work only can get the blue one to work as of now… Thank you

PImage myElonStart, myMonroe, myLennon, 
  myBlueCan, myRedCan, myPinkCan, myGreenCan, myTanCan, 
  mySave, myRestart, myBrush1, myBrush2, myBrush3;
PFont thePopArtFont;
boolean saveTheImage =false;

//***********COLORS*****************
color bluePaint = color(0, 144, 255);
color currentColor = color(0, 144, 255);
color black = color(0);
color redPaint = color(255, 4, 4);
color greenPaint = color (92, 207, 102);
color pinkPaint = color (253, 80, 116);
color tanPaint = color (245, 170, 91);
color orgBackground = color (255, 122, 10);


boolean typeIsCan=true;

void setup() {
  size (1280, 720);
  background(orgBackground);
  //load images
  myElonStart = loadImage("elonData.png");
  myMonroe = loadImage("monroeData.png");
  myLennon = loadImage("lennonData.png");
  myBlueCan = loadImage("blueCan.png");
  myRedCan = loadImage("redCan.png");
  myPinkCan = loadImage("pinkCan.png");
  myGreenCan = loadImage("greenCan.png");
  myTanCan = loadImage("tanCan.png");
  mySave = loadImage("save.png");
  myRestart = loadImage("restart.png");
  myBrush1 = loadImage("brush1.png");
  myBrush2 = loadImage("brush2.png");
  myBrush3 = loadImage("brush3.png");

  //load font
  thePopArtFont = createFont("GoldenHillsDEMO.ttf", 50);
  textFont(thePopArtFont);
}

void draw() {
  fill(black);
  text("Pop Art Paint Program", width/3, 50);
  fill(bluePaint);
  text("Pop Art Paint Program", width/3.01, 47);
  checkRollovers();
  myBorder();        //Draws blue border around window
  myDrawPeople();    //puts three pictures of options to paint
  myButtonLayout();

  if (mousePressed)
  {
    noStroke();
    fill(currentColor);
    if (typeIsCan)
    {
      if ((mouseX>10) && (mouseX<80) && (mouseY>5) && (mouseY<121))
      {
        fill(bluePaint);
        ellipse(mouseX, mouseY, 20, 20);
        ellipse(pmouseX, pmouseY, 40, 40);
      }
    } else
    {
      fill(currentColor);
      ellipse(mouseX, mouseY, 20, 20);
      line(pmouseX, pmouseY, mouseX, mouseY);
    }
  }
}

void mousePressed() {

  if ((mouseX>10) && (mouseX<80) && (mouseY>5) && (mouseY<121))
  {
    typeIsCan =false;
    currentColor = bluePaint;
  }
}
void checkRollovers () {
  //Save button rollover
  if ((mouseX >155) && (mouseX <250) && (mouseY >618) && (mouseY <718)) {
    saveTheImage=true;
    cursor(WAIT);
  } else {
    saveTheImage=false;
    cursor(ARROW);
  }
}
void mouseReleased() {
  if (saveTheImage == true) {
    saveImage();
   background(redPaint);

    saveTheImage = false;
  }
  
}

void myBorder() {
  fill(0, 144, 255);
  noStroke();
  rect(0, 0, 100, 611);
  rect(0, 610, 1280, 720);
  rect(1180, 0, 1280, 620);
}

void myButtonLayout() {
  //Paint Cans
  image(myBlueCan, 10, 5);
  image(myRedCan, 10, 128);
  image(myPinkCan, 10, 250);
  image(myGreenCan, 10, 374);
  image(myTanCan, 10, 495);
  //Paint Brushes
  image(myBrush1, 1200, 136);
  image(myBrush2, 1200, 260);
  image(myBrush3, 1200, 382);
  //Start Restart Button
  image(mySave, 155, 615);
  image(myRestart, 870, 615);
}

void myDrawPeople() {
  image(myElonStart, 156, 219);
  image(myMonroe, 520, 220);
  image(myLennon, 840, 220);
}

 void saveImage() {
  PImage partialSave = get(115, 65, 1000, 535);

  String path = sketchPath("Images/");

  File file = new File(path);
  int folderSize = 0;
  if (file.exists() && file.isDirectory()) {
    folderSize = file.listFiles().length;
  }
  partialSave.save(path+"PopArtImage" + folderSize + "jpg");
}![blueCan|77x116](upload://7eTMlQ5zagBXIbc4xQ5q93MsQbQ.png) ![brush1|60x60](upload://p9bycQ5Z5AouFyF0FEU6wdJ3DdP.png) ![brush2|60x60](upload://lqtupt8G0f6w6SVleCC1f2SkoJw.png) ![brush3|60x60](upload://mwqs9mubhRFfHIm0xfF2kHNkLTv.png) ![elonData|312x228](upload://lGZbaK64cv10ySP3jpauAnjW7RC.png) ![greenCan|77x116](upload://waMeSnPTf9zs0Liu5Ph5J5Xh68o.png) ![lennonData|312x228](upload://nVam0HHkOYTOzBY7q2UeNwglluu.png) ![monroeData|312x228](upload://7GBOwLEJMbhLt8EL4Cb6XsxZWY.png) ![pinkCan|77x116](upload://hUsQQ0eAr58cOyAcVFKxdQPcX50.png) ![redCan|77x116](upload://oIcnpq2tspvqyOqdKF0FUyO6YZq.png) ![restart|255x96](upload://izJl8ZZfRSoZknIfgmhp4Mk8VpA.png) ![save|100x100](upload://3klccvppF4im2DgdqUG5NjSqNF7.png) ![tanCan|77x116](upload://6JZ1RidEjTaBrGGp72fCLD8aXer.png) ![blueCan|77x116](upload://7eTMlQ5zagBXIbc4xQ5q93MsQbQ.png) ![brush1|60x60](upload://p9bycQ5Z5AouFyF0FEU6wdJ3DdP.png) ![brush2|60x60](upload://lqtupt8G0f6w6SVleCC1f2SkoJw.png) ![brush3|60x60](upload://mwqs9mubhRFfHIm0xfF2kHNkLTv.png) ![elonData|312x228](upload://lGZbaK64cv10ySP3jpauAnjW7RC.png) ![greenCan|77x116](upload://waMeSnPTf9zs0Liu5Ph5J5Xh68o.png) ![lennonData|312x228](upload://nVam0HHkOYTOzBY7q2UeNwglluu.png) ![monroeData|312x228](upload://7GBOwLEJMbhLt8EL4Cb6XsxZWY.png) ![pinkCan|77x116](upload://hUsQQ0eAr58cOyAcVFKxdQPcX50.png) ![redCan|77x116](upload://oIcnpq2tspvqyOqdKF0FUyO6YZq.png) ![restart|255x96](upload://izJl8ZZfRSoZknIfgmhp4Mk8VpA.png) ![save|100x100](upload://3klccvppF4im2DgdqUG5NjSqNF7.png) ![tanCan|77x116](upload://6JZ1RidEjTaBrGGp72fCLD8aXer.png) 
1 Like

Hi there Keeg23, welcome to the forum.

Unfortunately we can’t test your code because we don’t have the images nor the font. Best thing to do in these situations is rewrite a minimal version of your sketch which reproduces the problem, which doesn’t required external files such as images (and if the image is required, add it :slight_smile: )

Although I can’t run your code, I noticed the following:

void mouseReleased() {
  if (saveTheImage == true) {
    saveImage();
    background(redPaint);
    saveTheImage = false;
  }
}

The moment saveTheImage becomes true, it saves the image with the function saveImage();. Right after you’re telling your sketch to fill the background with a red colour. Does removing this solve your first issue?

1 Like

Minor thing, basically you are testing true == true or false == true. You could just type if (saveTheImage) {.

2 Likes