JavaScript p5 movement tracker

I am doing an exercise from Coding Traing Youtube channel. It is a ball with random movement that leaves it’s trail (movement history).

You can see the code here (click on canvas to get ball).

Here is a link to my code

As you can see I did most things the same way, but I used classes for creating balls. He used for tracker an array with pushing vectors into it, so did I. However my tracker is not showing the full history always just the place where ball is in current moment (so u can’t see anything unless tracker is bigger than ball herself).

I was looking at the code entire day and couldn’t find a solution. Would be grateful for help if anybody finds the problem.

1 Like


This happens because you’re clearing the history every time you call tracker.
Move the history array to the constructor:

constructor(size = 20) {
    this.history = [];
    this.x = width / 2;
    this.y = height / 2;
    this.size = size;

and remove it from tracker() (line 43).


Ouch I understand. Thank you so much for your help and explanation. :grinning: