Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add invlerp() and remap() functions to pygame.math #2649

Closed
bigwhoopgames opened this issue Jan 3, 2024 · 0 comments · Fixed by #2654
Closed

Add invlerp() and remap() functions to pygame.math #2649

bigwhoopgames opened this issue Jan 3, 2024 · 0 comments · Fixed by #2654

Comments

@bigwhoopgames
Copy link

bigwhoopgames commented Jan 3, 2024

Now that the lerp function has been implemented into pygame.math I thought it would also be a good idea to add the invlerp and remap functions.

def inv_lerp(a: float, b: float, v: float) -> float:
    return (v - a) / (b - a)

def remap(i_min: float, i_max: float, o_min: float, o_max: float, v: float) -> float:
    t = inv_lerp(i_min, i_max, v)
    return lerp(o_min, o_max, t)

inv_lerp is opposite of lerp and remap utilizes both to map a value from an input range to an output range. Very useful if you want to remap things like colors or percents etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant