Blunaxela
United States
 
 
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main(int argc, char** argv)
{
if (argc < 3) {
fprintf(stderr, "usage: %s <image width> <pixel width>\n", argv[0]);
exit(EXIT_FAILURE);
}

int image_width = strtol(argv[1], NULL, 0);
int pixel_width = strtol(argv[2], NULL, 0);

printf("P6\n%d %d\n255\n", image_width, image_width);
fflush(stdout);

int rand_fd = open("/dev/urandom", O_RDONLY);
if (rand_fd < 0) {
fprintf(stderr, "failed to open /dev/urandom\n");
exit(EXIT_FAILURE);
}

int r, c, rc;
char pixel;
int blocks_per_row = image_width/pixel_width;
for (r = 0; r < blocks_per_row; r++) {
char pixel_row[blocks_per_row][3];
int p;
for (p = 0; p < blocks_per_row; p++) {
int ret = read(rand_fd, pixel_row

, 3);
if (ret < 0) {
fprintf(stderr, "rand_fd bad read\n");
close(rand_fd);
exit(EXIT_FAILURE);
}
}

for (rc = 0; rc < pixel_width; rc++) {
for (c = 0; c < blocks_per_row; c++) {
for (p = 0; p < pixel_width; p++) {
write(STDOUT_FILENO, pixel_row[c], 3);
}
}
}
}

close(rand_fd);

exit(EXIT_SUCCESS);
}

Currently Online
Recent Activity
11 hrs on record
last played on 27 Feb
0.6 hrs on record
last played on 15 Feb
1.1 hrs on record
last played on 2 Feb