# VectorLerp for walking on a path

**URL:** <https://discourse.processing.org/t/vectorlerp-for-walking-on-a-path/22660>\
**Category:** Processing.py\
**Created:** [July 16, 2020, 11:41am UTC](https://discourse.processing.org/t/vectorlerp-for-walking-on-a-path/22660 "2020-07-16T11:41:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)\
**Post date:** [July 16, 2020, 11:41am UTC](https://discourse.processing.org/t/vectorlerp-for-walking-on-a-path/22660/1 "2020-07-16T11:41:25Z")

</div>

@jeremydouglass posted this example somewhere on this forum, and I enjoyed porting it to Python mode. That’s the post.

 ![sketch_2020_07_15a](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/17bd3ec1605f85a245630dc61fd881bbdc56a239.gif)

```auto
# LerpVectorsSimplified
# 2019-04 Processing 3.4 - based on LerpVectorsExample by Jeremy Douglass
# 2020-07 ported to Python Mode by Alexandre Villares

vecs = []

def setup():
    size(200, 200)
    # mark path points
    vecs.append(PVector(10, 10))
    vecs.append(PVector(width - 10, 10))
    vecs.append(PVector(width - 10, height - 10))
    vecs.append(PVector(10, height - 10))
    vecs.append(PVector(width / 2, height / 2))
    fill(0, 0, 255)

def draw():
    background(255)
    time = millis() / 2 % 4000 # a clock that counts up to 4000 and starts over
    # from -1 to 1, then starts over
    sawtoothWave = map(time, 0, 3999, -1, 1)
    triangleWave = abs(sawtoothWave) # bounces 0-1-0-1-0
    # find our location in 2D path based on 0-1
    loc = lerpVectors(triangleWave, vecs)
    ellipse(loc.x, loc.y, 20, 20) # draw at the location

# based on an amount, find the location along a path made of points
def lerpVectors(amt, vecs):
    if len(vecs) == 1:
        return vecs[0]
    cunit = 1.0 / (len(vecs) - 1)
    return PVector.lerp(vecs[floor(amt / cunit)],
                        vecs[ceil(amt / cunit)],
                        amt % cunit / cunit)

```
