[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Re: Starting the pygame 2 series



This can be done already using a lambda:

color_lerp = lambda pct: color.lerp(color2, pct)


On Mon, Jul 15, 2019, 13:56 Sam Bull <pygame@xxxxxxxxxxx> wrote:
On Mon, 2019-07-15 at 01:32 +0200, René Dudfield wrote:
> Thanks to @charlesoblack (first time contributor ya!) there is a
> pygame.Color.lerp() function now. It returns a linear interpolation.
>
> >>> color.lerp(color2, 0.0) -> color
>
> >>> color.lerp(color2, 0.5) -> halfway_color
>
> >>> color.lerp(color2, 1.0) -> color2

That's handy. I wonder if it might even be worth taking it a step further, so
you can just pass an object to a function to update the color progressively
(i.e. it doesn't need to know the color, it just updates the progress value),
such as:

   color_lerp = ColorLerp(color1, color2)
   progress = 0
   while progress < 1:
       progress += 0.1
       set_col(color_lerp.lerp(progress))


Or anything along those lines...