The simplest algorithm for generating fragment images
This article provides a complete C language code for generating a fragment image file, which is extremely simple. I believe this should be the simplest algorithm for generating fragment images. most of the fragment Image Code is also very short, but it is hard to understand it when recursive iterations exist. this code is easy to understand, and the images it generates will be unexpected. copy the Code # include <iostream> # include <cmath> # include <cstdlib> # define DIM 1000 void pixel_write (int, int); FILE * fp; int main () {fp = fopen ("image. ppm "," wb "); if (! Fp) {return-1;} fprintf (fp, "P6 \ n % d \ n255 \ n", DIM, DIM); for (int j = 0; j <DIM; j ++) {for (int I = 0; I <DIM; I ++) {pixel_write (I, j) ;}} fclose (fp ); return 0;} void pixel_write (int I, int j) {static unsigned char color [3]; float t = j + I * 0.001f; memcpy (color, & t, 3); fwrite (color, 1, 3, fp); // In fact, the simpler method is: // fwrite (& t, 1, 3, fp );} after the code is copied and run, an image file in the PPM format is generated. The simplest fragment image should be a three-part Cantor, but the line segment is continuously divided into two parts. as shown in: The image generated by this algorithm is similar to the three-point set. in particular, its green channel: After the code is modified, its fractal effect will be more obvious: copy the code void pixel_write (int I, int j) {static unsigned char color [3]; float t = j/4 + I * 0.001f; memcpy (color, & t, 3); fwrite (color, 1, 3, fp );}