I've made this little program were if you press the mouse all these balls execute from a while loop. If I click on the 0, 0 coordinates of the canvas I get all the balls going to the center of the screen which is fine but I want this to happen when you click in the center of the screen instead on the 0, 0 coordinates of the canvas.
As a second "improvement" I would like to make the 0, 0 coordinates follow the mouse position on the canvas. I guess this must be done with the translate function but I'm not able to do it.
I'm slowly learning how to code so apologize if my code looks terrible... hehe
Thank you!
void setup() {
size(screen.width, screen.height);
ellipseMode(CENTER);
colorMode(HSB);
background(174, 25, 0);
smooth();
}
void draw() {
// Background Fade Out Effect
frameRate(8);
fill(174, 25, 0, 30);
noStroke();
rect(0, 0, width, height);
// Pelotitas Function Calling
if(mousePressed) {
pelotitas(mouseX/2, mouseY/2);
}
}
void pelotitas(int x, int y) {
// Variables declaration
float i = random(50);
float u = random(50);
int j = 15;
// Translation to make circle in the middle of the screen, not in 0,0
I'm learning to code so I'm sure my question must be really silly to answer for any of you.
I've made function called "rectangles" that randomly creates some rectangles on the canvas. I want these rectangles to be reloaded everytime I click the mouse or press a key (the example has been done with the mouse). I've also drawn a rectangle with the same color than the canvas which I located on the draw function with an opacity of 20 to make some sort of fade out effect. My problem is that everything works fine if I click only once, if I make further clicks nothing happens... any help? I've been struggling with this and I can't find a solution.