Problem with fill() square (like a button)
in
Programming Questions
•
1 year ago
hi,
*** I have a new question in my comment ***
I want to click on square and make him black (in start it's white)when I click it's make all the square black but when I leave it's go back to white so I want to know how to fill just one when I click (when I leave it's stay black) how can I do that ???
- float x = 100;
- float y = 50;
- float w = 50;
- float h = 50;
- int count=0;
- void setup() {
- size(500, 500);
- background(255);
- stroke(0);
- noFill();
- fill(255);
- }
- void draw() {
- background(255);
- for (int i=0;i<60*7;i=i+60) {
- for (int j=0;j<60*5;j=j+60) {
- rect(x+j, y+i, w, h);
- }
- }
- if (mousePressed) {
- for (int j=0;j<7*60;j=j+60) {
- for (int i=0;i<5*60;i=i+60) {
- if (mouseX>x+i && mouseX <x+w+i && mouseY>y+j&& mouseY <y+h+j) {
- println("Row="+mouseX+" Column"+mouseY);
- println("button number ("+((i/60)+1)+","+((j/60)+1)+") was pressed");
- fill(0);
- }
- }
- }
- }
- else{
- fill(255);
- }
- }
1