Painting Program

Hey! I'm relatively new to Processing & programming in general. I'm trying to build a painting program that paints with a pink dot and the screen clears with a click. I couldn't find any examples of this problem on the internet. Help?

Here's the code:

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

void draw(){ if (mousePressed) { background(0); }else{ background(0);

}ellipse(mouseX,mouseY,33,33); if(mousePressed) { fill(0); }else{ fill(250,0,209); } }

Tagged:

Answers

  • I can see a problem from start. If you click to clear, then you will clear every time you paint.

    I would suggest to come up with another method. While mousePressed, draw. When mouseReleased: stop drawing. With a double click, reset.

    boolean drawOn=false;
    int radius =33;
    int t0_click;
    int double_click_time=250; // double click if two clickws withing this time window
    
    void setup() { 
      size (500, 500); 
      noStroke();
      background(0);
      fill(250,200,200);
    
      t0_click=millis();
    }
    
    void draw() { 
    
      if(drawOn==true)
        ellipse(mouseX, mouseY, radius, radius); 
    
    }
    
    void mousePressed(){
      drawOn=true;
    }
    
    void mouseReleased(){
      if(millis()-t0_click < double_click_time)
        background(0);
    
      drawOn=false;    
      t0_click=millis();
    }
    

    One more thing. To format code in this forum, select your code and press ctrl+o. i hope this helps,

    Kf

  • Thank you!

Sign In or Register to comment.