Created
July 12, 2025 11:27
-
-
Save MurageKibicho/804cbdaf0823059df713486b63a377d2 to your computer and use it in GitHub Desktop.
Starter code for Wu's line-drawing algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdint.h> | |
#include <math.h> | |
#define STB_IMAGE_WRITE_IMPLEMENTATION | |
#include "stb_image_write.h" | |
typedef struct point_struct Point; | |
typedef uint32_t RGBA; | |
struct point_struct | |
{ | |
int x; | |
int y; | |
}; | |
int main() | |
{ | |
char *outputFile = "output.png"; | |
int width = 512; | |
int height = 512; | |
int channels = 4; | |
//Create image with white background | |
uint8_t *pixels = malloc(width * height * channels); | |
for(int i = 0; i < width * height * channels; i += channels) | |
{ | |
pixels[i + 0] = 255; // R | |
pixels[i + 1] = 255; // G | |
pixels[i + 2] = 255; // B | |
if(channels == 4) | |
{ | |
pixels[i + 3] = 255; // A | |
} | |
} | |
//Write image to file | |
stbi_write_png(outputFile, width, height, channels, pixels, width * channels); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment