lewis.core.approaches
Defines functions that model typical behavior, such as a value approaching a target linearly at a certain rate.
Members
This function returns the new value after moving towards target at the given speed constantly for the time dt. |
- lewis.core.approaches.linear(current: float, target: float, rate: float, dt: float)[source]
This function returns the new value after moving towards target at the given speed constantly for the time dt.
If for example the current position is 10 and the target is -20, the returned value will be less than 10 if rate and dt are greater than 0:
new_pos = linear(10, -20, 10, 0.1) # new_pos = 9
The function makes sure that the returned value never overshoots:
new_pos = linear(10, -20, 10, 100) # new_pos = -20
- Parameters:
current – The current value of the variable to be changed.
target – The target value to approach.
rate – The rate at which the parameter should move towards target.
dt – The time for which to calculate the change.
- Returns:
The new variable value.