Skip to content

Instantly share code, notes, and snippets.

@pat36
Created May 4, 2019 18:15
Show Gist options
  • Save pat36/86526415f18249113710b3df8eccb9fe to your computer and use it in GitHub Desktop.
Save pat36/86526415f18249113710b3df8eccb9fe to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#define HEIGHT 640
#define WIDTH 480
#define FIELDS 3
int main(int argc, char** argv) {
FILE* f_img;
srand(time(nullptr));
unsigned char pix[HEIGHT][WIDTH][FIELDS] = {0};
for(int i = 0; i < HEIGHT; i++) {
for(int j = 0; j < WIDTH; j++) {
for(int h = 0; h < FIELDS; h++)
pix[i][j][h] = std::rand();
}
}
f_img = fopen("random_image.ppm", "wb");
fprintf(f_img, "P6\n");
fprintf(f_img, "%d %d\n", WIDTH, HEIGHT);
fprintf(f_img, "255\n");
fwrite(pix,1, HEIGHT*WIDTH*FIELDS,f_img);
fclose(f_img);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment