bukowski bukowski - 1 month ago 5
Java Question

get coordinate of clicked points on Processing 3

What I want to do is simply change the color of pixels I've clicked. So there are two states ;

mouse clicked

mouse not clicked

I'm using code below ;

boolean myBol = false ;
void setup(){
size(860,640);
background(0);
}
void draw(){
if (mousePressed) {

if(myBol == true){myBol = false;} else {myBol = true;}

}

if (myBol == true){
stroke(255);
point(mouseX,mouseY);
}}


When I run this code after first click it keeps drawing where ever I move the mouse but what I want is ; "draw everytime I click on screen".
enter image description here

Answer

Your check condition are not correct.

if (mousePressed) {
   if(myBol == true){
       myBol = false;
   } else {
       myBol = true;
   }
} 

or basicly

if (mousePressed)
    myBol = !myBol

Will change the myBol value on each click.

Since you want to draw on click, no need of this value. Just use the mousePressed value directly

if (mousePressed) {
    stroke(255);
    point(mouseX,mouseY);
}