diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-22 23:55:57 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-22 23:55:57 +0100 |
| commit | 91ab3ae0147712b549e4ec086818f847fd23e12f (patch) | |
| tree | 7b2dae9f288e1f7c6b3dc7c0101b4651fd0cf85d /README.md | |
| parent | 3c62d3d54244731b641952bd7e93edbab16d5d79 (diff) | |
| download | nonstd-91ab3ae0147712b549e4ec086818f847fd23e12f.tar.gz | |
Add PPM simple image implementation
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -19,6 +19,7 @@ ergonomic and productive. It aims to be C99 compliant. - **Memory Arena**: Simple block-based arena allocator for bulk memory management. - **File I/O**: Helper functions to read and write entire files with a single call. - **Logging**: Simple, leveled logging with ANSI colors and timestamps. +- **Canvas & PPM**: Simple 2D drawing API with PPM (ASCII) import/export. ## Installation @@ -184,6 +185,32 @@ LOG_ERROR_MSG("Connection failed"); // LOG_LEVEL=0 (ERROR) ... 3 (DEBUG) ``` +### 7. Canvas & PPM Images + +Create simple 2D images, draw shapes, and save to PPM (ASCII) format. + +```c +// Initialize a 400x400 canvas +Canvas canvas = ppm_init(400, 400); + +// Use predefined colors or HEX/RGB macros +ppm_fill(&canvas, COLOR_HEX(0x1a1a1a)); + +// Draw basic shapes +ppm_draw_rect(&canvas, 50, 50, 100, 100, COLOR_RED); +ppm_draw_circle(&canvas, 250, 100, 40, COLOR_BLUE); +ppm_draw_line(&canvas, 200, 200, 350, 350, COLOR_GREEN); +ppm_draw_triangle(&canvas, 50, 350, 150, 350, 100, 250, COLOR_YELLOW); + +// Save to file +if (ppm_save(&canvas, "output.ppm")) { + printf("Image saved successfully!\n"); +} + +// Clean up +ppm_free(&canvas); +``` + ## Testing The project includes a test suite using `minunit`. |
