The beauty of Fragment

Source: Internet
Author: User

The beauty of Fragment

Only when I see some websites engaged in the Fragment Art can I know that Z = z * z + C is so wonderful.
Then write it in opencv and check it out. The results are good. Haha.
In this small example, only the value of C can be modified. If you are interested, you can change the code to see if you can make some wonderful images.

Code tip: to obtain high-quality images, you can add image_w, but the performance is very low.

 

Image
 

Reference
Http://blog.csdn.net/spanzhang/
Http://www.fractal.net.cn/

Code

 

// Test. cpp: defines the entry point of the console application.
//

# Include "stdafx. H"
# Include "cv. H"
# Include "highgui. H"

Const int maid = 100;
Const double A = 0.0;
Const Double B = 0.0;
Const long Nmax = 255; // the critical value of Z attenuation (tends to be zero)
Const double rmax = 20; // The Z value increases (tends to be infinite) without boundaries

Iplimage * image = 0;
Int c_r_value = 60;
Int c_ I _value = 40;

// Return the number of iterations
Int getnum (int I, Int J)
{
Double c_realpart = (double) (c_r_value-50)/100*2*2; //-2 to + 2 // Julia set constant C
Double c_imagpart = (double) (c_ I _value-50)/100*2*2; //-2 to + 2 // Julia set constant C
Double realpart = (double) I/image_w +;
Double imagpart = (double) J/image_w + B;
Int n = 0;
While (n <Nmax)
{
// Z = z * z + C;
Double ZM = realpart * realpart + imagpart * imagpart;
If (ZM> rmax) break;
Double temp_realpart = realpart * realpart-imagpart * imagpart + c_realpart;
Double temp_imagpart = 2 * imagpart * realpart + c_imagpart;
Realpart = temp_realpart;
Imagpart = temp_imagpart;
N ++;
}
Return N;
}
Void onchangeimg (int pos)
{
Cvzero (image );
For (INT I = 0; I <image_w; I ++)
For (Int J = 0; j <image_w; j ++)
{
Int n1 = getnum (I, j );
Int n2 = getnum (J, I );
Int N3 = getnum (J, I/2 );
// Printf ("% d,", N );

Cvscalar SC1;
If (N1> Nmax-2) n1 = 0;
If (N2> Nmax-2) N2 = 0;
If (N3> Nmax-2) N3 = 0;

Sc1.val [0] = (INT) ABS (255 * (float) N1/Nmax );
Sc1.val [1] = (INT) ABS (255 * (float) N2/Nmax );
Sc1.val [2] = (INT) ABS (255 * (float) N3/Nmax );
Cvset2d (image, I, j, SC1 );

}

Double nvalue = cvnorm (image, 0, cv_c );

For (INT I = 0; I <image_w; I ++)
For (Int J = 0; j <image_w; j ++)
{
Cvscalar SC1;
Cvscalar SC2 = cvget2d (image, I, j );
Sc1.val [0] = (INT) ABS (255 * sc2.val [0]/nvalue );
Sc1.val [1] = (INT) ABS (255 * sc2.val [1]/nvalue );;
Sc1.val [2] = (INT) ABS (255 * sc2.val [2]/nvalue );;
Cvset2d (image, I, j, SC1 );
}

}
Int main (INT argc, char ** argv)
{

Cvnamedwindow ("win", 0 );
Cvcreatetrackbar ("C real", "win", & c_r_value, 100, onchangeimg );
Cvcreatetrackbar ("C imag", "win", & c_ I _value, 100, onchangeimg );

Image = cvcreateimage (cvsize (image_w, image_w), 8, 3 );
Onchangeimg (0 );

For (;;)
{

Cvshowimage ("win", image );
If (cvwaitkey (40) = 27) break;
}
Return 0;

}

 

Download

Opencv_share@163.com download
 

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.