Skip to content

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

Closed
@bigwhoopgames

Description

@bigwhoopgames

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions