Interaction Design WikiCreative Coding

Set max length of Racer trail

The following method can be used to set the maximum length of the Racer trail. Simply modify the age() method to check both the length of the line using the method below.

float calculateLength() {
  float _length = 0;
  PVector p1 = posList.get(0);
   
    for (int i=1; i < posList.size(); i++)
    {
     PVector p2 = posList.get(i);
      if (p1 != null && p2 != null)
         _length += dist(p1.x, p1.y, p2.x, p2.y);
      p1 = p2;
    }
    _length += dist( p1.x,  p1.y, curPos.x, curPos.y);
  return _length;
};