colour won't change when clicked

This is a painting program. It has a frame and colours at the bottom. I want the stroke to change to the colour of the image at the bottom when clicked. But it is not working. any suggestions? here is my code and images.

//Created by: Alessandra Macchione and Cristian Pertea
//Created on: May 20th, 2018
//Created for: Computer Science
//Final Assignment

PImage frame;
PImage red;
PImage orange;
PImage yellow;
PImage green;
PImage blue;
PImage purple;
PImage white;
PImage grey;
PImage black;
PImage eraser;
PImage brush;

//-------------------------------------------------------------------------

void setup() {
  frame = loadImage("frame.png");
  red = loadImage("red.png");
  orange = loadImage("orange.png");
  yellow = loadImage("yellow.png");
  green = loadImage("green.png");
  blue = loadImage("blue.png");
 // purple = loadImage("purple.png");
 // black = loadImage("black.png");
 // white = loadImage("white.png");
 // eraser = loadImage("eraser.png");
  brush = loadImage("brush.png");
  size(918, 790);
  background(#FAFEFF);
}

//-------------------------------------------------------------------------


void draw() {
  image(frame, 0, 0);
  image(red, 10, 735);
  image(orange, 60, 710);
  image(yellow, 110, 740);
  image(green, 160, 710);
  image(blue, 220, 738);
  //image(purple, 0, 0);
  //image(black, 0, 0);
  //image(grey, 0, 0);
  //image(white, 0, 0);
  //image(eraser, 0, 0);
  stroke(#E02A24);
  cursor(brush);
  if (mousePressed == true) {
    line(mouseX, mouseY, pmouseX, pmouseY);
  }

void mousePressed() {
  if (mouseX == 10 && mouseY == 735){
    stroke(#D6120B);
  }
  if (mouseX == 60 && mouseY == 710){
    stroke(#FF9A2E);
  }
  if (mouseX == 110 && mouseY == 740){
    stroke(#FFEB2E);
  }
  if (mouseX == 160 && mouseY == 710){
    loop();
    stroke(#99EA21);
  }
}


void keyPressed() {
  save("my_drawing.png");
}

frame red orange yellow green

Tagged:

Answers

  • Kill line 52

    Don’t say mouseX ==

    better >....&&....<.....

    There is a new forum now

  • new version

    instead of mouseX==...

    or mouseX>710 && mouseX<720

    I used dist()

    Chrisir ;-)

    // TO DO blue in mousePressed 
    
    
    //Created by: Alessandra Macchione and Cristian Pertea
    //Created on: May 20th, 2018
    //Created for: Computer Science
    //Final Assignment
    
    PImage frame;
    PImage red;
    PImage orange;
    PImage yellow;
    PImage green;
    PImage blue;
    PImage purple;
    PImage white;
    PImage grey;
    PImage black;
    PImage eraser;
    PImage brush;
    
    //-------------------------------------------------------------------------
    
    void setup() {
      size(918, 790);
      background(#FAFEFF);
    
      frame = loadImage("frame.png");
      red = loadImage("red.png");
      orange = loadImage("orange.png");
      yellow = loadImage("yellow.png");
      green = loadImage("green.png");
      blue = loadImage("blue.png");
      // purple = loadImage("purple.png");
      // black = loadImage("black.png");
      // white = loadImage("white.png");
      // eraser = loadImage("eraser.png");
      brush = loadImage("brush.png");
    }
    
    //-------------------------------------------------------------------------
    
    
    void draw() {
      //  image(frame, 0, 0);
      fill(0);
      textAlign(CENTER);
      text("red", 10, 735);
      text("orange", 60, 710);
      text("yellow", 110, 740);
      text("green", 160, 710);
      text("blue", 220, 738);
      //image(purple, 0, 0);
      //image(black, 0, 0);
      //image(grey, 0, 0);
      //image(white, 0, 0);
      //image(eraser, 0, 0);
      // stroke(#E02A24);
      // cursor(brush);
      if (mousePressed && mouseY < 700) {
        line(mouseX, mouseY, pmouseX, pmouseY);
      }
    }
    
    // -----------------------------------------------
    
    void mousePressed() {
      if (dist (mouseX, mouseY, 10, 735) < 19 ) {
        stroke(#D6120B);
      } else if (dist (mouseX, mouseY, 60, 710) < 19 ) {
        stroke(#FF9A2E);
      } else if (dist (mouseX, mouseY, 110, 740) < 19 ) {
        stroke(#FFEB2E);
      } else if (dist (mouseX, mouseY, 160, 710) < 19 ) {
        stroke(#99EA21);
      }
    }
    
    
    void keyPressed() {
      save("my_drawing.png");
    }
    //
    
Sign In or Register to comment.