PShape gauge_BW; PShape gauge_R; PShape gauge_G; PShape gauge_B; int BW_level; int R_level; int G_level; int B_level; int Y_BW; int Y_R; int Y_G; int Y_B; boolean RGB_switch; PImage switch_Pic_RGB; PImage switch_Pic_BW; int L; int H; void setup() { size(800, 500); switch_Pic_RGB = loadImage("rgb.jpg"); switch_Pic_BW = loadImage("bw.jpg"); L = width/18; // to get something "balanced", I will often use the value width/18 // so instead of writing it a lot of times, I name it L. It's shorter. H = height-50; // same here BW_level=0; R_level=0; G_level=0; B_level=0; Y_BW = H; Y_R = H; Y_G = H; Y_B = H; RGB_switch=false; } void draw() { BW_level = 255*( H - Y_BW)/( H - 100 ); R_level = 255*( H - Y_R)/( H - 100 ); G_level = 255*( H - Y_G)/( H - 100 ); B_level = 255*( H - Y_B)/( H - 100 ); fill(255); if (RGB_switch){ background(R_level,G_level,B_level); rect(0,0,width/2,height); image(switch_Pic_RGB,5,5); } else {background(BW_level); rect(0,0,width/2,height); image(switch_Pic_BW,5,5); } fill(0); textSize(20); text("B/W", L,height-20); text(BW_level,L,80); fill(255,0,0); text("R", 3.35*L,height-20); text(R_level,3*L,80); fill(0,255,0); text("G", 5.35*L,height-20); text(G_level,5*L,80); fill(0,0,255); text("B", 7.35*L,height-20); text(B_level,7*L,80); // I want to draw a gauge as a triangle. // here it's just 3 lines, not a shape, so the background doesn't change. line(L,H,L,100); line(L,100,2*L,100); line(2*L,100,L,H); // I'll draw the others as rectangles. // Here it's a shape (rect) so the background is of the color set by the last fill(). // If I don't change anything, it will be blue. fill(255); rect(3*L,100,L,H-100); rect(5*L,100,L,H-100); rect(7*L,100,L,H-100); } void mousePressed() { if(over_RGB_switch()){RGB_switch=!RGB_switch;} if(over_BW_gauge()) {Y_BW=mouseY;} if(over_R_gauge()) {Y_R=mouseY;} if(over_G_gauge()) {Y_G=mouseY;} if(over_B_gauge()) {Y_B=mouseY;} } void mouseDragged() { if(over_BW_gauge()) {Y_BW=mouseY;} if(over_R_gauge()) {Y_R=mouseY;} if(over_G_gauge()) {Y_G=mouseY;} if(over_B_gauge()) {Y_B=mouseY;} } boolean over_RGB_switch() { return (mouseX - 20)*(mouseX - 20) + (mouseY - 20)*(mouseY - 20) < 400; } boolean over_BW_gauge() { return mouseX>=L && mouseX<=2*L && mouseY>=100 && mouseY<=H; } boolean over_R_gauge() { return mouseX>=3*L && mouseX<=4*L && mouseY>=100 && mouseY<=H; } boolean over_G_gauge() { return mouseX>=5*L && mouseX<=6*L && mouseY>=100 && mouseY<=H; } boolean over_B_gauge() { return mouseX>=7*L && mouseX<=8*L && mouseY>=100 && mouseY<=H; }