summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSyndamia <kamen@syndamia.com>2026-03-28 22:52:45 +0200
committerSyndamia <kamen@syndamia.com>2026-03-28 22:52:45 +0200
commitfec9d432c13f72af24d78841779d73df18e86a73 (patch)
treea7d16a627d102bf339336dba0379c237deaac935
parent066c47c63f10df07fb31487e8cae325aec3ffa8e (diff)
downloadppm_graphics-fec9d432c13f72af24d78841779d73df18e86a73.tar
ppm_graphics-fec9d432c13f72af24d78841779d73df18e86a73.tar.gz
ppm_graphics-fec9d432c13f72af24d78841779d73df18e86a73.zip
feat: Add object interpolations, stabilize interpolation
-rw-r--r--AnimationRender/F_Interpolate.c38
-rw-r--r--AnimationRender/F_Interpolate.h9
-rw-r--r--RGBImage.h1
-rw-r--r--graphics.c15
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);
diff --git a/RGBImage.h b/RGBImage.h
index d3e5642..e2f9043 100644
--- a/RGBImage.h
+++ b/RGBImage.h
@@ -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;
diff --git a/graphics.c b/graphics.c
index 72089fc..d42e104 100644
--- a/graphics.c
+++ b/graphics.c
@@ -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);