Color Selecting

I am currently running into trouble having the color being selected and drawing… The colors will not work when pressed on? Not exactly sure why it is not working

PImage myElonStart, myMonroe, myLennon, 
  myBlueCan, myRedCan, myPinkCan, myGreenCan, myTanCan, 
  mySave, myRestart, myBrush1, myBrush2, myBrush3;
PFont thePopArtFont;
boolean saveTheImage =false;
boolean justSaved = 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(black);
    if (typeIsCan)
    {
      if ((mouseX>10) && (mouseX<80) && (mouseY>5) && (mouseY<121))
      {
        fill(bluePaint);
      } else {
        fill(bluePaint);
        ellipse(mouseX, mouseY, 20, 20);
        ellipse(pmouseX, pmouseY, 20, 20);
      }
      if ((mouseX>10) && (mouseX<80) && (mouseY>130) && (mouseY>246))
      {
        fill(redPaint);
      } else {
        fill(redPaint);
        ellipse(mouseX, mouseY, 20, 20);
        ellipse(pmouseX, pmouseY, 20, 20);
      }
    }
  }
}

1 Like

all the color and the brush ICONs are buttons.
when they are clicked you can set a number
for the color and brush size like

color paint=color(0);
int brush = 5;

void mousePressed() {
 if ( over(b1x,b1y,b1w,b1h) ) paint = color(200,0,0);  // RED button


 if ( over(b6x,b6y,b6w,b6h) ) brush = 15; // brush 1 button ( circle diameter select)
}

void draw() {
 fill(paint);
 circle(mouseX,mouseY,brush);
}

no PM for coding questions please

1 Like

So should I just delete the one section I have at the bottom of my code and set it up this way?

So get rid of this part??

if (mousePressed)
  {
    noStroke();
    fill(black);
    if (typeIsCan)
    {
      if ((mouseX>10) && (mouseX<80) && (mouseY>5) && (mouseY<121))
      {
        fill(bluePaint);
      } else {
        fill(bluePaint);
        ellipse(mouseX, mouseY, 20, 20);
        ellipse(pmouseX, pmouseY, 20, 20);
      }
      if ((mouseX>10) && (mouseX<80) && (mouseY>130) && (mouseY>246))
      {
        fill(redPaint);
      } else {
        fill(redPaint);
        ellipse(mouseX, mouseY, 20, 20);
        ellipse(pmouseX, pmouseY, 20, 20);
      }
    }
  }
}

sorry, it is just a idea how to restructure your program,
if you happy with the current structure or not understand what i want to show, ignore it.

To be honest I am just trying to get the color feature to work so when you click over the paint can it will select that color and will draw with it

yes, that is also what i try to show,
just not have the pictures…

color paint=color(0);
int brush = 5;
int b1x = 10, b1y = 10, b1w =80, b1h =30;
int b6x = 400, b6y = 10, b6w =80, b6h =30;

void setup() {
  size(500, 500);
  drawButtons();
  noStroke();
}

void draw() {
  fill(paint);
  circle(mouseX, mouseY, brush);
}

void mousePressed() {
  if ( over(b1x, b1y, b1w, b1h) ) paint = color(200, 0, 0);  // RED button

  if ( over(b6x, b6y, b6w, b6h) ) brush = 15; // brush 1 button ( circle diameter select)
}

void drawButtons() {
  fill(200, 0, 0);
  rect(b1x, b1y, b1w, b1h); // color RED button use ICON instead
  fill(255);
  rect(b6x, b6y, b6w, b6h); // brush 15 button use ICON instead
  fill(0);
  text("brush 15", b6x+3, b6y+b6h-5);  
}

boolean over(int x, int y, int w, int h) {
  return ( mouseX > x & mouseX < x + w &  mouseY > y & mouseY < y + h ) ;
}

but you can easy add them in / need to fix the bX settings also
like to ICON position and size
and use its variables for ICON position too.

anyhow that is a working program with a easier button operation.
run it to see how it works.