CodingTrain / CodingTrain/Suggestion-Box

implementation of an "Erase" Button function

Open
#1,661 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
570
Forks
85
PR merge metrics
No merged PRs in 30d

Description

Hello,

I have created the "Erase" button. The erase button when it's clicked should delete the drawing which is drawn by the mouse. It should work similarly to the paint program. I have used the following code and it does nothing to the functionality of the Erase button. So, if I draw something when the toggle is turned on and if I click the "Erase" button nothing is happening. Could someone please help me with this issue?

import controlP5.*;

ControlP5 cp5;

boolean onOff = false;

boolean erase = false;

void setup(){
size(1000, 1000);
background(255);
PFont font = createFont("Calibri", 15);


cp5 = new ControlP5(this);

cp5.addToggle("onOff").
setPosition(150, 20).
setSize(40, 15).
setFont(font).

setMode(ControlP5.SWITCH);

cp5.addButton("Erase").
setPosition(890, 20).
setSize(100, 30).
setFont(font);

}

void draw(){


fill(246, 246, 246);
stroke(246, 246, 246);
rect(0,0, 1000, 80);

stroke(0);
if (mousePressed == true && onOff == true) {
line(mouseX, mouseY, pmouseX, pmouseY);
}

}

void keyPressed(){
if(erase == true) {

background(255);
}
}

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.