Trails and background()

edited March 2018 in Questions about Code

Hi all,

Just doing a trivial example of a 2D random walker, and I want to keep on the screen the "past" of the walker. Simple enough, I though I just needed to call background(0) once in setup(), but this sketch only shows me a moving point with no history...

Can anyone tell me what am I missing? Can't believe getting stuck on something that simple -_-' Thanks a lot!


PVector walker;
float size=5;

void setup() {
  size(400,400);
  walker = new PVector(width/2,height/2);
  background(0);
}

void draw() {
  int i = floor(random(4));
  switch (i) {
    case 0:
      walker.x+=1;
    break;
    case 1:
      walker.x-=1;
    break;
    case 2:
      walker.y+=1;
    break;
    case 3:
      walker.y-=1;
    break;
  }
  fill(255);
  ellipse(walker.x,walker.y,size,size);
}

Answers

  • So I found out a solution, I was missing the "stroke(255);" statement. But I still don't get why the displayed "inside" of the ellipse doesn't stay on the sketch.

    Does anyone have any ideas to explain this?

    Thanks in advance!

  • The stroke covers the whole trail since you're not walking in increments larger than the stroke.

  • Thanks, I forgot that stroke color is set to 0 by default. The increment is indeed unnecessarily small and didn't help.

Sign In or Register to comment.