Create multiple custom rectangles in p5.js

I’m beginning to explore p5.js web editor, and I was wondering if there is a way to create multiple custom rectangles with mouse in canvas.That’s the only way I can think of. I want it be like Illustrator’s rectangle tool.:sob::sob::sob:

let clickX, clickY;

function setup() {
  createCanvas(600, 600);

function draw() {
  stroke(255, 0, 0);
  rect(clickX, clickY, mouseX - clickX, mouseY - clickY);

function mouseMoved() {
  clickX = mouseX;
  clickY = mouseY;

Hi, welcome to Forum !

First delete background(0); from your code, because it is every time clears screen. Second remove function mouseMoved. Do it with functions mousePressed and mouseDragged. It will solve your problem.