33 lines
620 B
C
33 lines
620 B
C
#include <stdlib.h>
|
|
|
|
#include "tuples.h"
|
|
|
|
struct canvas {
|
|
int width;
|
|
int height;
|
|
struct tuple * pixels;
|
|
};
|
|
|
|
struct canvas canvas(int width, int height)
|
|
{
|
|
return (struct canvas){
|
|
width,
|
|
height,
|
|
calloc(width * height, (sizeof (struct tuple)))
|
|
};
|
|
}
|
|
|
|
void canvas_write_pixel(struct canvas canvas, int x, int y, struct tuple color)
|
|
{
|
|
struct tuple * pixel = &canvas.pixels[y * canvas.width + x];
|
|
pixel->r = color.r;
|
|
pixel->g = color.g;
|
|
pixel->b = color.b;
|
|
pixel->a = color.a;
|
|
}
|
|
|
|
struct tuple canvas_pixel_at(struct canvas canvas, int x, int y)
|
|
{
|
|
return canvas.pixels[y * canvas.width + x];
|
|
}
|