The simplest algorithm for generating fragment images

Source: Internet
Author: User

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 );}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.