We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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");
}
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 ;-)