Hello, I have written these buttons that apply some filters to the image, since I can not have two filters active at a time, is it possible to disable the other when a new one is clicked, I cant figure it out by myself so you need your help.
Thanks in advance.
PImage img;
Button b1 = new Button(1, "Pixelation");
Button b2 = new Button(2, "Noise");
void setup()
{
size(500, 340);
textAlign(CENTER, CENTER);
img = loadImage("image.jpg");
}
void draw() {
background (255);
image(img, 0, 0);
b1.display();
b2.display();
}
void mouseClicked() {
b1.overButton();
b2.overButton();
}
class Button {
boolean selected = false;
int nr, x, y, w, h;
String name;
Button (int inNr, String inName) {
name = inName;
nr = inNr;
w = 70;
h = 20;
x = inNr*(w+10)-w;
y = 340-(h+10);
}
void display() {
if (selected) fill(90);
else fill(150);
rect(x, y, w, h);
fill(0);
text(name, x+(w/2), y+(h/2));
if (nr == 1 && selected) {
pixelation();
}
else if (nr == 2 && selected) {
noize();
}
}
void overButton() {
if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h)
Hello I am trying to create this class, that creates a button and when clicked changes the color of it. But the way I am doing it is not working, can you tell me what is wrong og tell me another way to achieve the same?
Thanks in advance
Button b1 = new Button(1, "Grayscale");
Button b2 = new Button(2, "Grayscale");
void setup()
{
size(500, 350);
textAlign(CENTER, CENTER);
}
void draw() {
b1.display();
b2.display();
}
class Button {
boolean selected = false;
int nr, x, y, w, h;
String name;
Button (int nr, String inName) {
name = inName;
w = 70;
h = 20;
x = nr*(w+10)-w;
y = 350-(h+10);
}
void display() {
if (selected) fill(255, 0, 0);
else fill(150);
rect(x, y, w, h);
fill(0);
text(name, x+(w/2), y+(h/2));
}
void mousePressed() {
if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h && selected == false) {
selected = true;
}
else if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h && selected == true) {
Hello, I have made some buttons, and I cant figure out how to make them change color when clicked, and when another button is clicked the other button will change back to it's original color.
Thanks in advance
color selected = 150;
void setup () {
size (500, 350);
textAlign(CENTER, CENTER);
}
void button (int nr, String text, int filter) {
int buttonW = 70;
int buttonH = 20;
int buttonX = nr*(buttonW+10)-buttonW;
int buttonY = height-(buttonH+10);
fill (selected);
rect (buttonX, buttonY, buttonW, buttonH);
fill (0);
text (text, buttonX+buttonW/2, buttonY+buttonH/2);