Generate an image using the code in the RD, GR, and BL methods (non-original, I just complete the Code), grbl

Source: Internet
Author: User

Generate an image using the code in the RD, GR, and BL methods (non-original, I just complete the Code), grbl
I open the source code of a piece in the ppm format, and find the tool that can be opened by myself .. (Non original, I processed the code, can directly execute the output, thumbnails can see the effect) This is the original blog http://news.cnblogs.com/n/501488/ I test can be in Visual Studio 2012 run ask a master question ,,
It is how to call the dynamic aspect name. The aspect names are suffixes and numbers,
We hope we can call different methods based on the dynamic aspect name...
I think it is too much repeated code. I want to use the C ++ class generic type, and I should be able to call the corresponding method.

 

The following is the C ++ code ,,,

# Include "stdafx. h "# include <iostream> # include <cmath> # include <cstdlib> # include <Windows. h> # pragma warning (disable: 4996) // disable all # pragma warning (disable: 4244) # define DIM 1024 # define DM1 (DIM-1) # define _ sq (x) * (x)/square # define _ cb (x) abs (x) * (x )) // absolute value of cube # define _ cr (x) (unsigned char) (pow (x), 1.0/3.0) // cube rootunsigned char GR (int, int); unsigned char BL (int, Int); unsigned char RD1 (int I, int j) {float x = 0, y = 0; int k; for (k = 0; k ++ <256 ;) {float a = x * x-y * y + (i-768.0)/512; y = 2 * x * y + (j-512.0)/512; x =; if (x * x + y * y> 4) break;} return log (k) * 47;} unsigned char GR1 (int I, int j) {float x = 0, y = 0; int k; for (k = 0; k ++ <256;) {float a = x * x-y * y + (i-768.0)/512; y = 2 * x * y + (j-512.0)/512; x = a; if (x * x + y * y> 4) break;} return log (k) * 47;} unsigned char BL1 (int I, int j) {float x = 0, y = 0; int k; for (k = 0; k + <256;) {float a = x * x-y * y + (i-768.0)/512; y = 2 * x * y + (j-512.0)/512; x = a; if (x * x + y * y> 4) break;} return 128-log (k) * 23;} unsigned char RD (int I, int j) {# define r (n) (rand () % n) static char c [1024] [1024]; return! C [I] [j]? C [I] [j] =! R (999 )? R (256): RD (I + r (2) % 1024, (j + r (2) % 1024): c [I] [j];} unsigned char GR (int I, int j) {static char c [1024] [1024]; return! C [I] [j]? C [I] [j] =! R (999 )? R (256): GR (I + r (2) % 1024, (j + r (2) % 1024): c [I] [j];} unsigned char BL (int I, int j) {static char c [1024] [1024]; return! C [I] [j]? C [I] [j] =! R (999 )? R (256): BL (I + r (2) % 1024, (j + r (2) % 1024): c [I] [j];} unsigned char RD2 (int I, int j) {double a = 0, B = 0, c, d, n = 0; while (c = a *) + (d = B * B) <4 & n ++ <880) {B = 2 * a * B + j * 8e-9 -. 645411; a = c-d + I * 8e-9 +. 356888;} return 255 * pow (N-80)/, 3 .);} unsigned char GR2 (int I, int j) {double a = 0, B = 0, c, d, n = 0; while (c = a *) + (d = B * B) <4 & n ++ <880) {B = 2 * a * B + j * 8e-9 -. 645411; a = c-d + I * 8e-9 +. 356888;} return 255 * pow (N-80)/800 ,. 7);} unsigned char BL2 (I Nt I, int j) {double a = 0, B = 0, c, d, n = 0; while (c = a *) + (d = B * B) <4 & n ++ <880) {B = 2 * a * B + j * 8e-9 -. 645411; a = c-d + I * 8e-9 +. 356888;} return 255 * pow (N-80)/800 ,. 5);} unsigned char RD3 (int I, int j) {static double k; k + = rand ()/1. /RAND_MAX; int l = k; l %= 512; return l> 255? 511-l: l;} unsigned char GR3 (int I, int j) {static double k; k + = rand ()/1. /RAND_MAX; int l = k; l %= 512; return l> 255? 511-l: l;} unsigned char BL3 (int I, int j) {static double k; k + = rand ()/1. /RAND_MAX; int l = k; l %= 512; return l> 255? 511-l: l;} unsigned char RD4 (int I, int j) {float s = 3. /(j + 99); float y = (j + sin (I * I + _ sq (j-700) * 5)/100. /DIM) * 35) * s; return (int (I + DIM) * s + y) % 2 + int (DIM * 2-i) * s + y) % 2) * 127;} unsigned char GR4 (int I, int j) {float s = 3. /(j + 99); float y = (j + sin (I * I + _ sq (j-700) * 5)/100. /DIM) * 35) * s; return (int (5 * (I + DIM) * s + y) % 2 + int (5 * (DIM * 2-i) * s + y) % 2) * 127;} unsigned char BL4 (int I, int j) {float s = 3. /(j + 99); float y = (j + sin (I * I + _ Sq (j-700) * 5)/100. /DIM) * 35) * s; return (int (29 * (I + DIM) * s + y) % 2 + int (29 * (DIM * 2-i) * s + y) % 2) * 127;} void pixel_write (int, int); FILE * fp; void pixel_write1 (int I, int j) {static unsigned char color [3]; color [0] = RD1 (I, j) & 255; color [1] = GR1 (I, j) & 255; color [2] = BL1 (I, j) & 255; fwrite (color, 1, 3, fp);} void pixel_write2 (int I, int j) {static unsigned char color [3]; color [0] = RD2 (I, j) & 255; color [1] = GR2 (I, j) & 255; color [2] = BL2 (I, j) & 255; fwrite (color, 1, 3, fp);} void pixel_write3 (int I, int j) {static unsigned char color [3]; color [0] = RD3 (I, j) & 255; color [1] = GR3 (I, j) & 255; color [2] = BL3 (I, j) & 255; fwrite (color, 1, 3, fp);} void pixel_write4 (int I, int j) {static unsigned char color [3]; color [0] = RD4 (I, j) & 255; color [1] = GR4 (I, j) & 255; color [2] = BL4 (I, j) & 255; fwrite (color, 1, 3, fp) ;}int main () {char T [256]; char printfHistory [2048] = "waiting for a file to be written"; printf_s ("printfHistory"); int num = 0; for (int a = 1; a <6; a ++) {sprintf_s (t, "MathPic % d. ppm ", a); fp = fopen (t," wb "); fprintf (fp," P6 \ n % d \ n255 \ n ", DIM, DIM ); for (int j = 0; j <DIM; j ++) {for (int I = 0; I <DIM; I ++) {switch (a) {case 1: pixel_write (I, j); case 2: pixel_write1 (I, j); case 3: pixel_write2 (I, j); case 4: pixel_write3 (I, j); case 5: pixel_write4 (I, j); default: break ;}} printf_s ("The % d image is successfully written! \ N ", a);} printf_s (" All images have been output. Open the program directory to view them! "); Fclose (fp); return 0;} void pixel_write (int I, int j) {static unsigned char color [3]; color [0] = RD (I, j) & 255; color [1] = GR (I, j) & 255; color [2] = BL (I, j) & 255; 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.