From 3c62d3d54244731b641952bd7e93edbab16d5d79 Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Thu, 22 Jan 2026 23:53:24 +0100 Subject: Add PPM simple image implementation --- examples/ppm.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 examples/ppm.c (limited to 'examples/ppm.c') diff --git a/examples/ppm.c b/examples/ppm.c new file mode 100644 index 0000000..95fafcf --- /dev/null +++ b/examples/ppm.c @@ -0,0 +1,29 @@ +#define NONSTD_IMPLEMENTATION +#include "../nonstd.h" + +int main() { + u32 width = 400; + u32 height = 400; + Canvas img = ppm_init(width, height); + + // Background + ppm_fill(&img, COLOR_HEX(0x1a1a1a)); + + // Draw some shapes + ppm_draw_rect(&img, 50, 50, 100, 100, CLR_RED); + ppm_draw_circle(&img, 250, 100, 40, CLR_BLUE); + ppm_draw_triangle(&img, 50, 350, 150, 350, 100, 250, CLR_YELLOW); + ppm_draw_line(&img, 200, 200, 350, 350, CLR_GREEN); + + // Random colors and macros + ppm_draw_rect(&img, 200, 250, 50, 80, COLOR_RGB(255, 165, 0)); + + if (ppm_save(&img, "example.ppm")) { + printf("Image saved to example.ppm\n"); + } else { + printf("Failed to save image\n"); + } + + ppm_free(&img); + return 0; +} -- cgit v1.2.3