diff options
| -rw-r--r-- | AnimationRender/F_Interpolate.c | 38 | ||||
| -rw-r--r-- | AnimationRender/F_Interpolate.h | 9 | ||||
| -rw-r--r-- | RGBImage.h | 1 | ||||
| -rw-r--r-- | graphics.c | 15 |
4 files changed, 59 insertions, 4 deletions
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); diff --git a/AnimationRender/F_Interpolate.h b/AnimationRender/F_Interpolate.h index e2ee4c5..2f68c53 100644 --- a/AnimationRender/F_Interpolate.h +++ b/AnimationRender/F_Interpolate.h @@ -2,6 +2,10 @@ #define F_INTERPOLATE #include "FrameCallback.h" +#include "../FrameRender/P_Square.h" +#include "../FrameRender/P_Circle.h" +#include "../FrameRender/P_Checker.h" +#include "../FrameRender/P_Image.h" #include "../FrameRender/P_TransformCenter.h" #include "../FrameRender/P_TransformRotate.h" @@ -16,6 +20,11 @@ typedef struct Interpolate { FrameCallback* Interpolate_setup(Interpolate obj); +void Interpolate_Square(Square* value, const Square* start, const Square* end, double progress); +void Interpolate_Circle(Circle* value, const Circle* start, const Circle* end, double progress); +void Interpolate_Checker(Checker* value, const Checker* start, const Checker* end, double progress); +void Interpolate_Image(Image* value, const Image* start, const Image* end, double progress); + void Interpolate_TransformCenter(TransformCenter* value, const TransformCenter* start, const TransformCenter* end, double progress); void Interpolate_TransformRotate(TransformRotate* value, const TransformRotate* start, const TransformRotate* end, double progress); @@ -16,6 +16,7 @@ typedef struct ARGB { void ARGB_merge(ARGB* bottom, color top); void ARGB_mergeARGB(ARGB* bottom, ARGB top); +void ARGB_set(ARGB* rgb, color color); typedef struct RGBImage { u32 width; @@ -62,12 +62,17 @@ main() { u32 sizeCallbacks = sizeof(callbacks) / sizeof(*callbacks); TransformCenter img1 = { .centerX = width / 8, .centerY = height * 3/5 }, - img2 = { .centerX = height * 3/5, .centerY = width / 8 }; + img2 = { .centerX = height / 8, .centerY = width / 8 }; TransformRotate r1 = { .angle = M_PI / 8 }, r2 = { .angle = M_PI * 2 }; + + Circle c1 = { .radius = 50, .color = 0x00FFFFFF, }, c2 = { .radius = 50, .color = 0xFFFFFFFF, }; + const FrameCallback* frameCallbacks[] = { - Draw_setup((Draw){ - .callbacks = (const PixelCallback**)callbacks, .sizeCallbacks = sizeCallbacks, + Interpolate_setup((Interpolate){ + .startValue = &c1, .endValue = &c2, + .value = callbacks[8]->callback_self, + .interpolate = (f_interpolate)Interpolate_Circle, }), FrameRange_setup((FrameRange){ .startFrame = 25, .endFrame = 125, @@ -86,6 +91,10 @@ main() { .value = callbacks[4]->callback_self, .interpolate = (f_interpolate)Interpolate_TransformRotate, }), + NULL, + Draw_setup((Draw){ + .callbacks = (const PixelCallback**)callbacks, .sizeCallbacks = sizeCallbacks, + }), }; u32 sizeFrameCallbacks = sizeof(frameCallbacks) / sizeof(*frameCallbacks); |
