神奇玫瑰花

  这是一段有意思的代码,执行之后是一朵玫瑰花,特在此分享一下,感兴趣的小伙伴可以自己试一下,代码真的很神奇,一定要坚持下去,才能发现它更多的奥秘?

#define _CRT_SECURE_NO_WARNINGS 1
#include
#include
#include
#include
#pragma comment(lib,"winmm.lib)
int rosesize = 500;
int h = -250;
struct DOT
{
double x;
double y;
double z;
double r;
double g;
};
bool calc(double a, double b, double c, DOT &d)
{
double j, n, o, w, z;
if (c > 60)
{
d.x = sin(a * 7)(13 + 5 / (0.2 + pow(b * 4, 4))) - sin(b) * 50;
d.y = b
rosesize + 50;
d.z = 625 + cos(a * 7)(13 + 5 / (0.2 + pow(b * 4, 4))) + b * 400;
d.r = a * 1 - b / 2;
d.g = a;
return true;
}
double A = a * 2 - 1;
double B = b * 2 - 1;
if (A
A + BB < 1)
{
if (c>37)
{
j = (int© & 1);
n = j ? 6 : 4;
o = 0.5 / (a = 0.01) + cos(b * 125) * 3 - a * 300;
w = b
h;
d.x = ocos(n) + wsin(n) + j * 610 - 390;
d.y = osin(n) - wcos(n) + 550 - j * 350;
d.z = 1180 + cos(B + A) * 99 - j * 300;
d.r = 0.4 - a0.1 + pow(1 - BB, -h * 6)0.15 - ab0.4 + cos(a + b) / 5 + pow(cos((o(a + 1) + (B > 0 ? w : -w)) / 25), 30)0.1(1 - BB);
d.g = o / 1000 + 0.7 - o
w0.000003;
return true;
}
if (c > 32)
{
c = c
1.16 - 0.15;
o = a * 45 - 20;
w = bbh;
z = osin© + wcos© + 620;
d.x = ocos© - wsin©;
d.y = 28 + cos(B0.5) * 99 - bbb * 60 - z / 2 - h;
d.z = z;
d.r = (b
b0.3 + pow(1 - (AA)), 7)0.15 + 0.3)b;
d.g = b
0.7;
return true;
}
o = A
(2 - b)(80 - c * 2);
w = 99 - cos(A) * 120 - cos(b)
(-h - c4.9) + cos(pow(1 - b, 7)) * 50 + c * 2;
z = o
sin© + wcos© + 700;
d.x = o
cos© - wsin©;
d.y = B * 99 - cos(pow(b, 7)) * 50 - c / 3 - z / 1.35 + 450;
d.z = z;
d.r = (1 - b / 1.2)0.9 + a0.1;
d.g = pow(1 - b), 20) / 4 + 0.05;
return true;
}
return false;
}
short
zBuffer;
int x, y, z, zBufferlndex;
DOT dot;
initgraph(640, 480);
mciSendString(“open BadApple.mp3 alias BadApple”, NULL, 0, NULL);
mciSendString(“play BAdApple”, NULL, 0, NULL);
setbkcolor(YELLOW);
cleardevice();
zBuffer = new short[rosesizerosesize];
memset(zBuffer, 0, sizeof(short)rosesizerosesize);
for (int j = 0; j < 2000; j++)//&&!_kbhit()
{
for (int i=0;i<10000;i++)
if (calc(double(rand()) / RAND_MAX, double(rand()) / RAND_MAX, rand() % 46 / 0.74, dot))
{
z = int(dot.z + 0.5);
x = int(dot.x
rosesize / z - h + 0.5);
y = int(dot.yrosesize / z - h + 0.5);
if (y>rosesize) continue;
zBufferlndex = y
rosesize + x;
if (!zBuffer[zBufferlndex] || zBuffer[zBufferlndex]>z)
{
zBuffer[zBufferlndex] = z;
int r = ~int((dot.rh));
if (r < 0) r = 0;
if (r>255) r = 255;
int b = ~int((dot.r
dot.r * 80));
if (b < 0) b = 0;
if (b>255) b = 255;
putpixel(x + 50, y - 20, RGB(r, g, b));

	}
}
Sleep(100);

}
delete[]zBuffer;
getchar();
closegraph();
return 0;
}

你可能感兴趣的:(编程之路,玫瑰花)