#include #include #include inline int OK(int x) { return x == 0; } ////RGBImage//// typedef uint8_t byte; typedef uint16_t byte2; typedef uint32_t byte4; typedef struct _RGB { byte r; byte g; byte b; } RGB; void ARGB_set(RGB* rgb, byte4 color) { rgb->r = (0xFF0000 & color) >> 16; rgb->g = (0x00FF00 & color) >> 8; rgb->b = (0x0000FF & color); } typedef struct _RGBImage { int width; int height; RGB* img; } RGBImage; RGBImage RGBImage_new(int width, int height) { return (RGBImage){ .width = width, .height = height, .img = malloc(sizeof(RGB) * width * height) }; } void RGBImage_free(RGBImage img) { free(img.img); } void RGBImage_delete(RGBImage* img) { RGBImage_free(*img); img->width = img->height = 0; img->img = NULL; } RGB* RGBImage_at(RGBImage img, int row, int col) { return img.img + (row % img.height) * img.width + col % img.width; } int ppm6_write(FILE* f, RGBImage img) { fprintf(f, "P6\n%d %d\n255\n", img.width, img.height); fwrite(img.img, sizeof(*img.img), img.width * img.height, f); return fflush(f); } ////main//// int main() { RGBImage frame = RGBImage_new(512, 512); for (int frameIndex = 0; frameIndex < 120; ++frameIndex) { for (int r = 0; r < frame.width; ++r) for (int c = 0; c < frame.height; ++c) { RGB* pixel = RGBImage_at(frame, r, c); if (((r + frameIndex) / 32 + (c + frameIndex) / 32) % 2 == 0) { ARGB_set(pixel, 0x000000); } else { ARGB_set(pixel, 0xFF00FF); } } ppm6_write(stdout, frame); } RGBImage_delete(&frame); return 0; }