Assignment from school

Use Processing to create a 1280 x 720 window for the program. Feel free to make this smaller if it does not fit on your display.

Left clicking in the window creates a circle with a random size, x-velocity, y-velocity, and colour. A circle class needs to be created in a separate tab to represent a circle and required functions.

Right clicking destroys any circle that has the mouse cursor inside of its area. How will you know if the mouse cursor is inside a circle? The dist() function in processing is your friend.

Use text to display in the window how many circles have been spawned, how many have been destroyed, and how many times the screen has been cleared.

Clicking the middle button clears all the circles but does not add to the “destroyed” stat.

Pushing ‘r’ resets the program to its initial state.

Circles need to bounce when they hit the edge of the window.

This was the assignment given to me by my teacher and I don’t know how to start it. All I’ve gotten so far is the 1280x720 window.

See Processing Overview \ - see Hello Mouse

And Objects \

Hey and welcome to the forum!

Great to have you here!

We can’t give you full code solutions… but we can help you with what you come up with…


You need to use the function size(1280,720);

for this you need to use the void function mousePressed. Inside you can use variable mouseButton to get if its left (==LEFT), middle (==center) or right (== RIGHT)

So to create multiple circles you need an array. I suggest four ArrayList<Float> or create two PVector arrays (one to get x & y, the other to get x speed & y speed) or create a class Ball. Since the requirement is a class, you need to add 3 functions inside of it; void display() {}, void move().

with the dist(mouseX,mouseY,circleX,circleY) you get the distance between the center of the circle and the cursor. If the dist() function returns value less then circleR (radius) it means the cursor is inside the circle. So inside the if() statement remove the current circle. I suggest you remove it while checking for it.

//inside the mousePressed() function
for(int i = 0; i < circles.size(); i++) {
   if(dist(<parameters>) < circles.get(i).r {

text() function draws text on the screen according to the parameters; textAlign(3,3) (to center the text), textSize() to set its size, font(PFont) to set font, fill() to set it’s color. So create a string and enter it into the text() function. The string must contain circles.size(), to get the number of the circles displayed, int spawnCounter (create it to keep track of the circles spawned, along with other -Counter variables), int destroyCounter and clearCounter. Whenever you for eg. add a circle, just add spawnCounter++ //or (+=1 or = spawnCounter + 1) to it.

To test for the middle button press use (mouseButton == CENTER) and call the circles.clear() and add 1 to clearCounter.

To test for key presses, use the function void keyPressed() and check for the button with if (key == char) or if(keyCode == LEFT) to check for arrow keys / backspace / enter / shift / ctrl / …
to reset the program clear the array the same way you did before, but also set -Counter variables to 0.

to achieve this check if circleX + circleR > width, set xSpeed to -xSpeed (or use *= -1). To check for the left side use circleY - circleR < 0 and do the same thing. You can fuse both and use circleX + circleR > width || circleY - circleR < 0 in an if statement. just swap circleX to circleY and width to height.

I hope this helps. It took far too long to write it all down even tho it is a simple program


It’s mandatory to create a class Circle.

1 Like

: P
After I wrote it I saw it so instead of deleting it, I just added the text

1 Like
textAlign(CENTER, CENTER);

is the same as

textAlign(3, 3);

textAlign() \ Language (API) \ Processing 3+

Example of where the numbers came from:


prints to the console:

37 3 39 101 102 0


1 Like