mouse action
in
Programming Questions
•
2 years ago
I'm trying to write a function for a class that would detect whether the mouse has clicked that object. Below is my code.
i want the fill to decrease by 1 each time that the mouse presses the circle. but I'm getting to many messages when the mouse is clicked because the speed of draw()
Maybe there is a quick fix that I can't think of?
- int count = 0;
- float gridsize;
- float diameter;
- float centerX, centerY;
- int currentFill;
- void setup() {
- size(500, 500);
- background(0);
- smooth();
- noStroke();
- diameter = width/3;
- centerX = width/2;
- centerY = height/2;
- currentFill = 255;
- }
- void draw() {
- fill(currentFill);
- ellipse(centerX, centerY, diameter, diameter);
- mouseTest();
- }
- void mouseTest() {
- if(mousePressed == true && mouseX >= (centerX - diameter/2) && mouseX <= (centerX + diameter/2)
- && mouseY >= (centerY - diameter/2) && mouseY <= (centerY + diameter/2)) {
- currentFill = currentFill - 1;
- println(currentFill);
- }
- }
1