From fec9d432c13f72af24d78841779d73df18e86a73 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 28 Mar 2026 22:52:45 +0200 Subject: feat: Add object interpolations, stabilize interpolation --- AnimationRender/F_Interpolate.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'AnimationRender/F_Interpolate.c') diff --git a/AnimationRender/F_Interpolate.c b/AnimationRender/F_Interpolate.c index 890279c..3cb3b5a 100644 --- a/AnimationRender/F_Interpolate.c +++ b/AnimationRender/F_Interpolate.c @@ -25,7 +25,43 @@ FrameCallback* Interpolate_setup(Interpolate obj) { return fca; } -#define NUM_INTERPOLATE(a, b, perc) ((a) * (1.0 - (perc)) + (b) * (perc)) +#define NUM_INTERPOLATE(a, b, perc) ((a) == (b) ? (a) : ((a) * (1.0 - (perc)) + (b) * (perc))) + +color +colorInterpolate(color ina, color inb, double percentage) { + ARGB a, b; + ARGB_set(&a, ina); + ARGB_set(&b, inb); + + a.a = NUM_INTERPOLATE(a.a, b.a, percentage); + a.r = NUM_INTERPOLATE(a.r, b.r, percentage); + a.g = NUM_INTERPOLATE(a.g, b.g, percentage); + a.b = NUM_INTERPOLATE(a.b, b.b, percentage); + + return a.a << 24 | a.r << 16 | a.g << 8 | a.b; +} + +void Interpolate_Square(Square* value, const Square* start, const Square* end, double progress) { + value->size = NUM_INTERPOLATE(start->size, end->size, progress); + value->color = colorInterpolate(start->color, end->color, progress); +} + +void Interpolate_Circle(Circle* value, const Circle* start, const Circle* end, double progress) { + value->radius = NUM_INTERPOLATE(start->radius, end->radius, progress); + value->color = colorInterpolate(start->color, end->color, progress); +} + +void Interpolate_Checker(Checker* value, const Checker* start, const Checker* end, double progress) { + value->squareSize = NUM_INTERPOLATE(start->squareSize, end->squareSize, progress); + value->colorA = colorInterpolate(start->colorA, end->colorA, progress); + value->colorB = colorInterpolate(start->colorB, end->colorB, progress); +} + +void Interpolate_Image(Image* value, const Image* start, const Image* end, double progress) { + value->scale = NUM_INTERPOLATE(start->scale, end->scale, progress); + if (start->img.img != end->img.img) + fprintf(stderr, "Refusing to interpolate between images!"); +} void Interpolate_TransformCenter(TransformCenter* value, const TransformCenter* start, const TransformCenter* end, double progress) { value->centerX = NUM_INTERPOLATE(start->centerX, end->centerX, progress); -- cgit v1.2.3