diff options
Diffstat (limited to 'examples/ppm.c')
| -rw-r--r-- | examples/ppm.c | 29 |
1 files changed, 29 insertions, 0 deletions
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 @@ | |||
| 1 | #define NONSTD_IMPLEMENTATION | ||
| 2 | #include "../nonstd.h" | ||
| 3 | |||
| 4 | int main() { | ||
| 5 | u32 width = 400; | ||
| 6 | u32 height = 400; | ||
| 7 | Canvas img = ppm_init(width, height); | ||
| 8 | |||
| 9 | // Background | ||
| 10 | ppm_fill(&img, COLOR_HEX(0x1a1a1a)); | ||
| 11 | |||
| 12 | // Draw some shapes | ||
| 13 | ppm_draw_rect(&img, 50, 50, 100, 100, CLR_RED); | ||
| 14 | ppm_draw_circle(&img, 250, 100, 40, CLR_BLUE); | ||
| 15 | ppm_draw_triangle(&img, 50, 350, 150, 350, 100, 250, CLR_YELLOW); | ||
| 16 | ppm_draw_line(&img, 200, 200, 350, 350, CLR_GREEN); | ||
| 17 | |||
| 18 | // Random colors and macros | ||
| 19 | ppm_draw_rect(&img, 200, 250, 50, 80, COLOR_RGB(255, 165, 0)); | ||
| 20 | |||
| 21 | if (ppm_save(&img, "example.ppm")) { | ||
| 22 | printf("Image saved to example.ppm\n"); | ||
| 23 | } else { | ||
| 24 | printf("Failed to save image\n"); | ||
| 25 | } | ||
| 26 | |||
| 27 | ppm_free(&img); | ||
| 28 | return 0; | ||
| 29 | } | ||
