diff options
| author | Syndamia <kamen@syndamia.com> | 2026-03-16 20:59:04 +0200 |
|---|---|---|
| committer | Syndamia <kamen@syndamia.com> | 2026-03-16 20:59:04 +0200 |
| commit | ef4a2773e90ebc6ed7ad66bcfd4e30165c04fb93 (patch) | |
| tree | f2ee90c08ae5f11692bd6c3ccf85077aab465e6b | |
| parent | 2202e87c466803eeaddd974006aa9950d8e0d067 (diff) | |
| download | ppm_graphics-ef4a2773e90ebc6ed7ad66bcfd4e30165c04fb93.tar ppm_graphics-ef4a2773e90ebc6ed7ad66bcfd4e30165c04fb93.tar.gz ppm_graphics-ef4a2773e90ebc6ed7ad66bcfd4e30165c04fb93.zip | |
feat: Implement circle and rename square
| -rw-r--r-- | AnimationInterpolate.c | 4 | ||||
| -rw-r--r-- | AnimationObject.c | 13 | ||||
| -rw-r--r-- | AnimationObject.h | 17 | ||||
| -rw-r--r-- | RGBImage.c | 2 | ||||
| -rw-r--r-- | RGBImage.h | 5 | ||||
| -rw-r--r-- | graphics.c | 13 |
6 files changed, 35 insertions, 19 deletions
diff --git a/AnimationInterpolate.c b/AnimationInterpolate.c index 2ff4a8b..f24c678 100644 --- a/AnimationInterpolate.c +++ b/AnimationInterpolate.c @@ -3,8 +3,8 @@ #define NUM_INTERPOLATE(a, b, perc) (a * (1.0 - (perc)) + b * (perc)) -byte4 -colorInterpolate(byte4 ina, byte4 inb, double percentage) { +color +colorInterpolate(color ina, color inb, double percentage) { ARGB a, b; ARGB_set(&a, ina); ARGB_set(&b, inb); diff --git a/AnimationObject.c b/AnimationObject.c index af3798b..16489c3 100644 --- a/AnimationObject.c +++ b/AnimationObject.c @@ -20,7 +20,7 @@ AO_CheckerPattern(const Animation* anim, u32 frameIndex, ARGB pixel, i32 r, i32 ARGB AO_Square(const Animation* anim, u32 frameIndex, ARGB pixel, i32 r, i32 c, void* priv) { - struct AO_SquareSettings* set = (struct AO_SquareSettings*)priv; + struct AO_Square* set = (struct AO_Square*)priv; if (0 <= r && r <= set->width && 0 <= c && c <= set->height) { ARGB_set(&pixel, set->color); @@ -30,6 +30,17 @@ AO_Square(const Animation* anim, u32 frameIndex, ARGB pixel, i32 r, i32 c, void* } ARGB +AO_Circle(const Animation* anim, u32 frameIndex, ARGB pixel, i32 r, i32 c, void* priv) { + struct AO_Circle* cir = (struct AO_Circle*)priv; + + if (r * r + c * c < cir->radius * cir->radius) { + ARGB_set(&pixel, cir->color); + } + + return pixel; +} + +ARGB AO_Image(const Animation* anim, u32 frameIndex, ARGB pixel, i32 r, i32 c, void* priv) { struct AO_Image img = *(struct AO_Image*)priv; diff --git a/AnimationObject.h b/AnimationObject.h index cec9268..95aa115 100644 --- a/AnimationObject.h +++ b/AnimationObject.h @@ -5,20 +5,27 @@ struct AO_CheckerPattern { u32 squareSize; - byte4 colorA; - byte4 colorB; + color colorA; + color colorB; }; ARGB AO_CheckerPattern(const Animation* anim, u32 frameIndex, ARGB pixel, i32 r, i32 c, void* priv); -struct AO_SquareSettings { +struct AO_Square { u32 width; u32 height; - byte4 color; + color color; }; ARGB AO_Square(const Animation* anim, u32 frameIndex, ARGB pixel, i32 r, i32 c, void* priv); +struct AO_Circle { + double radius; + color color; +}; + +ARGB AO_Circle(const Animation* anim, u32 frameIndex, ARGB pixel, i32 r, i32 c, void* priv); + struct AO_Image { RGBImage img; double zoom; @@ -32,7 +39,7 @@ struct AO_Line { double b; double c; double width; - byte4 color; + color color; }; ARGB AO_Line(const Animation* anim, u32 frameIndex, ARGB pixel, i32 r, i32 c, void* priv); @@ -4,7 +4,7 @@ #include <stdlib.h> void -ARGB_set(ARGB* rgb, byte4 color) { +ARGB_set(ARGB* rgb, color color) { rgb->a = (0xFF000000 & color) >> 24; rgb->r = (0x00FF0000 & color) >> 16; rgb->g = (0x0000FF00 & color) >> 8; @@ -5,8 +5,7 @@ #include <stdio.h> typedef uint8_t byte; -typedef uint16_t byte2; -typedef uint32_t byte4; +typedef uint32_t color; typedef struct ARGB { byte a; @@ -15,7 +14,7 @@ typedef struct ARGB { byte b; } ARGB; -void ARGB_set(ARGB* rgb, byte4 color); +void ARGB_set(ARGB* rgb, color color); void ARGB_merge(ARGB* bottom, ARGB top); typedef struct RGBImage { @@ -66,7 +66,7 @@ main() { Animation_pushEvent(&anim, 0, 120, A_Interpolate, &i1); // Yellow square - struct AO_SquareSettings s1 = { + struct AO_Square s1 = { .width = 20, .height = 20, .color = 0xFFFFFF00, }; struct AM_MoveSpin ms1 = { @@ -82,21 +82,20 @@ main() { }; Animation_pushEvent(&anim, 0, 80, AM_MoveLinear, &ml3); - // White square - struct AO_SquareSettings s4 = { - .width = 20, .height = 20, .color = 0xFFFFFFFF, + // White circle + struct AO_Circle s4 = { + .radius = 20, .color = 0xFFFFFFFF, }; struct AM_MoveLinear ml4 = { .startRow = 40, .startCol = 40, .dRow = 2, .dCol = 2, - .wrapCoordinates = true, - .callback = AO_Square, .priv = &s4, + .callback = AO_Circle, .priv = &s4, }; Animation_pushEvent(&anim, 0, 80, AM_MoveLinear, &ml4); // Green square - struct AO_SquareSettings s2 = { + struct AO_Square s2 = { .width = 35, .height = 50, .color = 0xA009FAA5, }; struct AM_MoveLinear ml2 = { |
