Graças ao DuckDuckGo Chat AI, ver AQUI, encontrei o código para gerar uma imagem aleatória. E se os pixeis vermelhos fossem neurónios a receber info e azuis quando emitem ? Como será o nosso cérebro à lupa ? Podemos fazer hoje muito mais do que o Sr. Professor e Doutor Egas Monis.
Código gerado pelo DuckDuckGo AI, uma imagem aleatória de 10000x10000
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define WIDTH 10000
#define HEIGHT 10000
void create_random_ppm(const char *filename) {
// Open a file to write the PPM image
FILE *fp = fopen(filename, "wb");
if (!fp) {
fprintf(stderr, "Failed to open output file\n");
return;
}
// Write the PPM header
fprintf(fp, "P6\n%d %d\n255\n", WIDTH, HEIGHT);
// Seed the random number generator
srand(time(NULL));
// Write random pixel data
for (int y = 0; y < HEIGHT; y++) {
for (int x = 0; x < WIDTH; x++) {
unsigned char r = rand() % 256; // Red
unsigned char g = rand() % 256; // Green
unsigned char b = rand() % 256; // Blue
fwrite(&r, sizeof(unsigned char), 1, fp);
fwrite(&g, sizeof(unsigned char), 1, fp);
fwrite(&b, sizeof(unsigned char), 1, fp);
}
}
// Close the file
fclose(fp);
}
int main() {
create_random_ppm("random_image.ppm");
printf("Random PPM image generated: random_image.ppm\n");
return 0;
}

Comentários
Postar um comentário