剁手节已经过去几天了,当天成交量达到了恐怖的2000多亿,不知道大家贡献了多少呢?然而大家还有多少人记得双十一是光棍节呢?广大单身汪同胞还在苦苦挣扎,“大!家!不!要!慌!”今天就给大家带来一个绝佳的礼物,用来跟妹子表白,让大家早点脱离单身汪的生活。 (感谢我吧,这可不容易哦~~~)
那么今天的神秘礼物是什么呢?大家猜猜送妹子什么最好呢? (送什么都不如送玫瑰花呀~~~)没错,今天给大家带来的就是一多缓慢绽放的玫瑰花!话不多说,先看图:
编辑
编辑
编辑
看起来是不是挺不错的呢!大家是不是觉得就结束了呢? “当!然!不!是!”如果只有一朵花怎么能衬托出这中氛围呢?来首音乐才有情调嘛!然后我们再添加一首音乐!一边听着音乐,一边看着一朵玫瑰的绽放,是不是特有情调?(音乐不能截图,有需要的自己来找我吧)也许你就能从此告白成功,脱离单身,走向幸福的两人世界哦!(没成功当我没说(━┳━ _ ━┳━))
好了下面来看下源码:
#include
#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 + B*B < 1)
{
//绿叶
if (c > 37)
{
j = (int(c) & 1);
n = j ? 6 : 4;
o = 0.5 / (a + 0.01) + cos(b * 125) * 3 - a * 300;
w = b * h;
d.x = o * cos(n) + w * sin(n) + j * 610 - 390;
d.y = o * sin(n) - w * cos(n) + 550 - j * 350;
d.z = 1180 + cos(B + A) * 99 - j * 300;
d.r = 0.4 - a * 0.1 + pow(1 - B * B, -h * 6) * 0.15 - a * b * 0.4 + cos(a + b) / 5 +
pow(cos((o * (a + 1) + (B > 0 ? w : -w)) / 25), 30) * 0.1 * (1 - B * B);
d.g = o / 1000 + 0.7 - o * w * 0.000003;
return true;
}
//花萼
if (c > 32)
{
c = c*1.16 - 0.15;
o = a * 45 - 20;
w = b * b * h;
z = o * sin(c) + w * cos(c) + 620;
d.x = o * cos(c) - w * sin(c);
d.y = 28 + cos(B * 0.5) * 99 - b * b * b * 60 - z / 2 - h;
d.z = z;
d.r = (b * b * 0.3 + pow((1 - (A * A)), 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 - c * 4.9) + cos(pow(1 - b, 7)) * 50 + c * 2;
z = o * sin(c) + w * cos(c) + 700;
d.x = o * cos(c) - w * sin(c);
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 + a * 0.1;
d.g = pow((1 - b), 20) / 4 + 0.05;
return true;
}
return false;
}
int main()
{
short *zBuffer;
intx, y, z, zBufferIndex;
DOTdot;
initgraph(640,480);//创建绘图窗口
mciSendString(L"open ./素材/音乐.mp3 alias BGM",0,0,0);//打开音乐 L 多字节字符串
mciSendString(L"play BGM repeat",0,0,0);
setbkcolor(LIGHTRED);
cleardevice();
zBuffer = new short[rosesize * rosesize];
memset(zBuffer, 0, sizeof(short) * rosesize * rosesize);
for (int j = 0; j < 2000 && !_kbhit(); j++)
{
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.y*rosesize / z - h + 0.5);
if (y > rosesize) continue;
zBufferIndex = y*rosesize + x;
if (!zBuffer[zBufferIndex] || zBuffer[zBufferIndex] > z)
{
zBuffer[zBufferIndex] = z;
//画点
int r = ~int((dot.r*h));if (r < 0)r = 0;if (r > 255)r = 255;
int g = ~int((dot.g*h));if (g < 0)g = 0;if (g > 255)g = 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(10);
}
delete[]zBuffer;
_getch();
closegraph();
return 0;
}
这就是程序的全部代码啦!如果想更换音乐只要改下你想要替换的音乐名字改为【音乐】就好了,当然了格式必须是MP3格式的才可以哦。如果想学习C/C++可以点击原文链接来找我哦~~~