-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathinterpolate.py
40 lines (32 loc) · 994 Bytes
/
interpolate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Linear Interpolation.
#
# Move the mouse across the screen and the symbol will follow. Between
# drawing each frame of the animation, the ellipse moves part of the
# distance (0.05) from its current position toward the cursor using
# the lerp() function
#
# This is the same as the Easing under input only with lerp() instead.
from p5 import *
x, y = 0, 0
def setup():
size(640, 360)
title("Interpolate")
no_stroke()
def draw():
global x
global y
background(51)
# lerp() calculates a number between two numbers at a specific
# increment. The `amount` parameter is the amount to interpoate
# between the two values where 0 is equal to the first point, 0.1
# is very near the first point, 0.5 is half-way between, etc.
#
# Here we are moving 5% of the way to the mouse location each
# frame.
#
x = lerp(x, mouse_x, 0.05)
y = lerp(y, mouse_y, 0.05)
fill(255)
circle((x, y), 66)
if __name__ == '__main__':
run()