Persistent Shape with Mouse?

No, it’s not obvious.

It has to do with the usage of background(255); at beginning of draw().

Here is a solution that has background(255); and stores the points and draws them throughout.


ArrayList<PVector> points = new ArrayList ();

void setup() { 
  size(800, 800);
}// function 

void draw() { 
  background(255); 

  fill(255, 0, 0);
  text("Hello ", 19, 19);

  ellipse(mouseX, mouseY, 
    4, 4);

  fill(2, 0, 230);
  for (int i = 0; i<points.size(); i++) {
    PVector pv1 = points.get(i);
    ellipse(pv1.x, pv1.y, 4, 4);
  }//for
}// function draw()

void mousePressed() {
  points.add(new PVector(mouseX, mouseY));
}// function
3 Likes