bukowski bukowski - 1 year ago 82
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(){
void draw(){
if (mousePressed) {

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


if (myBol == true){

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 Source

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) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download