summaryrefslogtreecommitdiff
path: root/graphics.c
diff options
context:
space:
mode:
authorSyndamia <kamen@syndamia.com>2026-03-28 23:49:45 +0200
committerSyndamia <kamen@syndamia.com>2026-03-28 23:49:45 +0200
commit7bca1ce8c15c3a5892aa44624d270f6ae8d35aaa (patch)
treeea3f50abb889c668d8d701bde622f87340337fd5 /graphics.c
parentaa16453072477ed1f90def01bdd55bebac696f61 (diff)
downloadppm_graphics-7bca1ce8c15c3a5892aa44624d270f6ae8d35aaa.tar
ppm_graphics-7bca1ce8c15c3a5892aa44624d270f6ae8d35aaa.tar.gz
ppm_graphics-7bca1ce8c15c3a5892aa44624d270f6ae8d35aaa.zip
feat: Implement line segment and make node moving animation
Diffstat (limited to 'graphics.c')
-rw-r--r--graphics.c92
1 files changed, 47 insertions, 45 deletions
diff --git a/graphics.c b/graphics.c
index d7e5ebd..4b1a470 100644
--- a/graphics.c
+++ b/graphics.c
@@ -11,6 +11,7 @@
#include "FrameRender/P_Checker.h"
#include "FrameRender/P_Circle.h"
#include "FrameRender/P_Image.h"
+#include "FrameRender/P_LineSegment.h"
#include "FrameRender/P_Square.h"
#include "FrameRender/P_TransformCenter.h"
#include "FrameRender/P_TransformRotate.h"
@@ -24,75 +25,77 @@ int
main() {
u32 width = 512;
u32 height = 512;
+ const u32 FPS = 60;
+ u32 frames = FPS * 5;
- FILE* fbclc = fopen("bclc.ppm", "rb");
- RGBImage bclc = ppm_read(fbclc);
- fclose(fbclc);
+ TransformCenter childLeft = { .centerX = width / 4, .centerY = height * 3 / 4, };
+ TransformCenter childRight = { .centerX = width * 3 / 4, .centerY = height * 3 / 4, };
+ LineSegment segmentRight = {
+ .aX = width / 2, .aY = height / 4,
+ .bX = width * 3 / 4, .bY = height * 3 / 4,
+ .width = 10, .color = 0xFFFF00FF,
+ };
+ LineSegment segmentLeft = {
+ .aX = width / 2, .aY = height / 4,
+ .bX = width / 4, .bY = height * 3 / 4,
+ .width = 10, .color = 0xFFFF00FF,
+ };
PixelCallback* callbacks[] = {
- Checker_setup((Checker){
- .squareSize = 64, .colorA = 0xFF000000, .colorB = 0xFFFF00FF,
- }),
- TransformCenter_setup((TransformCenter){
- .centerX = width / 2, .centerY = height / 2,
- }),
- Square_setup((Square){
- .size = 100, .color = 0xFFFFFF00,
- }),
- NULL,
- TransformRotate_setup((TransformRotate){
- .angle = M_PI / 8,
- }),
+ /* Background */
Square_setup((Square){
- .size = 200, .color = 0xFF00FFFF,
+ .size = width, .color = 0xFFF0F0F0,
}),
- NULL,
+ /* Root node */
TransformCenter_setup((TransformCenter){
- .centerX = width * 3/4, .centerY = height / 2,
+ .centerX = width / 2, .centerY = height / 4,
}),
Circle_setup((Circle){
- .radius = 50, .color = 0x80FFFFFF,
+ .radius = 60, .color = 0xFFFF0000,
}),
+ /* Child node */
NULL,
- TransformCenter_setup((TransformCenter){
- .centerX = width / 8, .centerY = height * 3/5,
+ TransformCenter_setup(childRight),
+ Circle_setup((Circle){
+ .radius = 60, .color = 0xFF00FF00,
}),
- Image_setup((Image){
- .img = bclc,
- .scale = 0.2,
+ /* Connecting line */
+ NULL,
+ LineSegment_setup((LineSegment){
+ .aX = width / 2, .aY = height / 4,
+ .bX = width * 3 / 4, .bY = height * 3 / 4,
+ .width = 10, .color = 0xFFFF00FF,
}),
};
u32 sizeCallbacks = sizeof(callbacks) / sizeof(*callbacks);
- TransformCenter img1 = { .centerX = width / 8, .centerY = height * 3/5 },
- 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, };
-
FrameCallback* frameCallbacks[] = {
- Interpolate_setup((Interpolate){
- .startValue = &c1, .endValue = &c2,
- .value = callbacks[8]->callback_self,
- .interpolate = (f_interpolate)Interpolate_Circle,
- }),
FrameRange_setup((FrameRange){
- .startFrame = 25, .endFrame = 125,
+ .startFrame = frames / 3 - FPS, .endFrame = frames / 3,
}),
Interpolate_setup((Interpolate){
- .startValue = &img1, .endValue = &img2,
- .value = callbacks[10]->callback_self,
+ .startValue = &childRight, .endValue = &childLeft,
+ .value = callbacks[4]->callback_self,
.interpolate = (f_interpolate)Interpolate_TransformCenter,
}),
+ Interpolate_setup((Interpolate){
+ .startValue = &segmentRight, .endValue = &segmentLeft,
+ .value = callbacks[7]->callback_self,
+ .interpolate = (f_interpolate)Interpolate_LineSegment,
+ }),
NULL,
FrameRange_setup((FrameRange){
- .startFrame = 0, .endFrame = 50,
+ .startFrame = frames * 2 / 3 - FPS, .endFrame = frames * 2 / 3,
}),
Interpolate_setup((Interpolate){
- .startValue = &r1, .endValue = &r2,
+ .startValue = &childLeft, .endValue = &childRight,
.value = callbacks[4]->callback_self,
- .interpolate = (f_interpolate)Interpolate_TransformRotate,
+ .interpolate = (f_interpolate)Interpolate_TransformCenter,
+ }),
+ Interpolate_setup((Interpolate){
+ .startValue = &segmentLeft, .endValue = &segmentRight,
+ .value = callbacks[7]->callback_self,
+ .interpolate = (f_interpolate)Interpolate_LineSegment,
}),
NULL,
Draw_setup((Draw){
@@ -101,9 +104,8 @@ main() {
};
u32 sizeFrameCallbacks = sizeof(frameCallbacks) / sizeof(*frameCallbacks);
- RenderAnimation(width, height, 150, (const FrameCallback**)frameCallbacks, sizeFrameCallbacks);
+ RenderAnimation(width, height, frames, (const FrameCallback**)frameCallbacks, sizeFrameCallbacks);
- RGBImage_delete(&bclc);
for (u32 i = 0; i < sizeCallbacks; ++i) {
if (callbacks[i] == NULL) continue;
free(callbacks[i]->callback_self);