making changes stay
in
Programming Questions
•
7 months ago
Hi All!! I have been trying to create an interactive menu: every button should change some settings in the webcam. The only problem is that the changes remain only as long as the mouse is pressed.
What should I do??
Thanks!!!
There is the code...
//--------- DECLARING VARIALBLES
// DECLARING VARIABLES FOR IMAGES, BUTTONS AND SPECIFICS
import processing.video.*;
int TopButtonY, BottomButtonY, Button1x, Button2x, Button3x, Button4x, Button5x, Button6x, Button7x, Button8x, Button9x;
Capture cam;
void setup() {
size(640, 536, P2D);
cam = new Capture(this,width, height);
cam.start();
// INIZIALIZING COORDINATES OF BUTTONS
TopButtonY=(480);
BottomButtonY=(536);
Button1x=0;
Button2x=8;
Button3x=158;
Button4x=166;
Button5x=316;
Button6x=324;
Button7x=474;
Button8x=482;
Button9x=632;
}
//--------- DRAWING BUTTONS and SHOWING // ADD TEXT TO BUTTONS
void draw() {
if (cam.available() == true) {
cam.read ();
image(cam,0,0);
//TopButtonY
stroke(150);
fill(150);
rect(0,480,640,10);
//Button1x
stroke(150);
fill(150);
rect(0,480+8,8,40);
//Button2x
stroke(0,0,255);
fill(0,0,255);
rect(8,480+8,150,40);
//Button3x
stroke(150);
fill(150);
rect(158,480+8,8,40);
//Button4x
stroke(0,0,255);
fill(0,0,255);
rect(166,480+8,150,40);
//Button5x
stroke(150);
fill(150);
rect(316,480+8,8,40);
//Button6x
stroke(0,0,255);
fill(0,0,255);
rect(324,480+8,150,40);
//Button7x
stroke(150);
fill(150);
rect(474,480+10,8,40);
//Button8x
stroke(0,0,255);
fill(0,0,255);
rect(482,480+8,150,40);
//Button9x
stroke(150);
fill(150);
rect(632,480+8,8,40);
//BottomButtonY
stroke(150);
fill(150);
rect(0,480+48,640,10);
if (cam.available() == true) {
cam.read ();
cam.loadPixels();
loadPixels();
}
}
}
// ------- BUTTONS INTERACTIONS WITH MOUSE
// BUTTON 1
//CHANGE PIXELS COLOUR TO GREEN IF BUTTON 1 PRESSED
void mousePressed() {
if( (mouseY>TopButtonY) && (mouseY<BottomButtonY)) {
//SE ALL'INTERNO DEL BOTTONE 2X
if((mouseX>Button2x)&&(mouseX<Button3x)) {
// TURN BUTTON GREEN WHEN PRESSED
stroke(0,255,0);
fill(0,255,0);
rect(8,480+8,150,40);
// I WILL CHANGE CAMERA SETTINGS HERE
}
}
//BUTTON 2
//CHANGE PIXELS COLOUR TO GREEN IF BUTTON 2 PRESSED
if(mouseY>TopButtonY) {
if((mouseX>Button4x)&(mouseX<Button5x)) {
// TURN BUTTON GREEN WHEN PRESSED
stroke(0,255,0);
fill(0,255,0);
rect(166,480+8,150,40);
// I WILL CHANGE CAMERA SETTINGS HERE
}
}
//BUTTON 3
if(mouseY>TopButtonY) {
if((mouseX>Button6x)&(mouseX<Button7x)) {
// TURN BUTTON GREEN WHEN PRESSED
stroke(0,255,0);
fill(0,255,0);
rect(324,480+8,150,40);
// I WILL CHANGE CAMERA SETTINGS HERE
}
}
// BUTTON 4
if(mouseY>TopButtonY) {
if((mouseX>Button8x)&(mouseX<Button9x)) {
// TURN BUTTON GREEN WHEN PRESSED
stroke(0,255,0);
fill(0,255,0);
rect(482,480+8,150,40);
// I WILL CHANGE CAMERA SETTINGS HERE
}
}
}
What should I do??
Thanks!!!
There is the code...
//--------- DECLARING VARIALBLES
// DECLARING VARIABLES FOR IMAGES, BUTTONS AND SPECIFICS
import processing.video.*;
int TopButtonY, BottomButtonY, Button1x, Button2x, Button3x, Button4x, Button5x, Button6x, Button7x, Button8x, Button9x;
Capture cam;
void setup() {
size(640, 536, P2D);
cam = new Capture(this,width, height);
cam.start();
// INIZIALIZING COORDINATES OF BUTTONS
TopButtonY=(480);
BottomButtonY=(536);
Button1x=0;
Button2x=8;
Button3x=158;
Button4x=166;
Button5x=316;
Button6x=324;
Button7x=474;
Button8x=482;
Button9x=632;
}
//--------- DRAWING BUTTONS and SHOWING // ADD TEXT TO BUTTONS
void draw() {
if (cam.available() == true) {
cam.read ();
image(cam,0,0);
//TopButtonY
stroke(150);
fill(150);
rect(0,480,640,10);
//Button1x
stroke(150);
fill(150);
rect(0,480+8,8,40);
//Button2x
stroke(0,0,255);
fill(0,0,255);
rect(8,480+8,150,40);
//Button3x
stroke(150);
fill(150);
rect(158,480+8,8,40);
//Button4x
stroke(0,0,255);
fill(0,0,255);
rect(166,480+8,150,40);
//Button5x
stroke(150);
fill(150);
rect(316,480+8,8,40);
//Button6x
stroke(0,0,255);
fill(0,0,255);
rect(324,480+8,150,40);
//Button7x
stroke(150);
fill(150);
rect(474,480+10,8,40);
//Button8x
stroke(0,0,255);
fill(0,0,255);
rect(482,480+8,150,40);
//Button9x
stroke(150);
fill(150);
rect(632,480+8,8,40);
//BottomButtonY
stroke(150);
fill(150);
rect(0,480+48,640,10);
if (cam.available() == true) {
cam.read ();
cam.loadPixels();
loadPixels();
}
}
}
// ------- BUTTONS INTERACTIONS WITH MOUSE
// BUTTON 1
//CHANGE PIXELS COLOUR TO GREEN IF BUTTON 1 PRESSED
void mousePressed() {
if( (mouseY>TopButtonY) && (mouseY<BottomButtonY)) {
//SE ALL'INTERNO DEL BOTTONE 2X
if((mouseX>Button2x)&&(mouseX<Button3x)) {
// TURN BUTTON GREEN WHEN PRESSED
stroke(0,255,0);
fill(0,255,0);
rect(8,480+8,150,40);
// I WILL CHANGE CAMERA SETTINGS HERE
}
}
//BUTTON 2
//CHANGE PIXELS COLOUR TO GREEN IF BUTTON 2 PRESSED
if(mouseY>TopButtonY) {
if((mouseX>Button4x)&(mouseX<Button5x)) {
// TURN BUTTON GREEN WHEN PRESSED
stroke(0,255,0);
fill(0,255,0);
rect(166,480+8,150,40);
// I WILL CHANGE CAMERA SETTINGS HERE
}
}
//BUTTON 3
if(mouseY>TopButtonY) {
if((mouseX>Button6x)&(mouseX<Button7x)) {
// TURN BUTTON GREEN WHEN PRESSED
stroke(0,255,0);
fill(0,255,0);
rect(324,480+8,150,40);
// I WILL CHANGE CAMERA SETTINGS HERE
}
}
// BUTTON 4
if(mouseY>TopButtonY) {
if((mouseX>Button8x)&(mouseX<Button9x)) {
// TURN BUTTON GREEN WHEN PRESSED
stroke(0,255,0);
fill(0,255,0);
rect(482,480+8,150,40);
// I WILL CHANGE CAMERA SETTINGS HERE
}
}
}
1