Add another shape with each mouse click! Help!



I am just starting out with coding and I have to create a simple program in code that accomplishes the following guidelines:
“Count the number of mouse presses in the canvas and use that to change the number of
shapes drawn for each frame such that more mouse presses means more shapes.”

this is what I have so far:

int numberOfPresses = 0;
PShape square;

void setup(){
  size(300, 300);
  square = createShape(RECT, random(300), random(300), 30, 30);

void mousePressed(){
  numberOfPresses = numberOfPresses + 1;
  println("ShapeCount: " + numberOfPresses);

void draw(){

I am able to count my mouse clicks, and create a random square within the space, however, I can’t figure out how to keep adding randomly placed squares with each new mouse click.
Any help would be greatly appreciated!!


Hi madeMcD,

You should have a look at the for loop structure. That’s how you’ll manage to draw several shape based on the number of mouse clicks.