Sj中国智造 发表于 2018-5-13 13:51:57

2018献给母亲的礼物

本帖最后由 Sj中国智造 于 2018-5-13 13:54 编辑

#include <windows.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <tchar.h>

#pragma comment(lib,"Winmm.lib")//播放音乐的
using namespace std;

float f(float x, float y, float z) {
        float a = x * x + 9.0f / 4.0f * y * y + z * z - 1;
        return a * a * a - x * x * z * z * z - 9.0f / 80.0f * y * y * z * z * z;
}

float h(float x, float z) {
        for (float y = 1.0f; y >= 0.0f; y -= 0.001f)
                if (f(x, y, z) <= 0.0f)
                        return y;
        return 0.0f;
}

int main()
{
        system("mode con cols=120 lines=40");
        HANDLE fd = GetStdHandle(STD_OUTPUT_HANDLE);
        CONSOLE_CURSOR_INFO cinfo;
        cinfo.bVisible = 0;
        cinfo.dwSize = 1;
        SetConsoleCursorInfo(fd, &cinfo);

        MessageBox(NULL, TEXT("开始前,请把电脑的声音开大!"), TEXT("即将开始...."), MB_ICONINFORMATION);

        MessageBox(NULL, TEXT("今天是2018年5月13日,妈妈,母亲节快乐!"), TEXT("开始"), MB_OK);

        mciSendString(TEXT("open \"./muqin.mp3\" alias mymusic"), NULL, 0, NULL);
        mciSendString(TEXT("play mymusic"), NULL, 0, NULL);


        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0C);
        HANDLE o = GetStdHandle(STD_OUTPUT_HANDLE);
        _TCHAR buffer = { _T(' ') };
        _TCHAR ramp[] = _T(".:-=+*#%@");
        int count = 0;
        int count1 = 0;

        double second = 270;
        int minute = int (second/60);
        for (float t = 0.0f;minute!=0; t += 0.1f) {
                int sy = 0;
                float s = sinf(t);//返回一个sin的浮点数
                float a = s * s * s * s * 0.2f;

                for (float z = 1.3f; z > -1.2f; z -= 0.1f) {
                        _TCHAR* p = &buffer;
                        float tz = z * (1.2f - a);
                        for (float x = -1.5f; x < 1.5f; x += 0.05f) {
                                float tx = x * (1.2f + a);
                                float v = f(tx, 0.0f, tz);
                                if (v <= 0.0f) {
                                        float y0 = h(tx, tz);
                                        float ny = 0.01f;
                                        float nx = h(tx + ny, tz) - y0;
                                        float nz = h(tx, tz + ny) - y0;
                                        float nd = 1.0f / sqrtf(nx * nx + ny * ny + nz * nz);
                                        float d = (nx + ny - nz) * nd * 0.5f + 0.5f;
                                        *p++ = ramp[(int)(d * 5.0f)];
                                }
                                else
                                        *p++ = ' ';
                        }
                }

                for (sy = 0; sy < 25; sy++) {
                        COORD coord = { 0, sy };
                        SetConsoleCursorPosition(o, coord);
                        WriteConsole(o, buffer, 79, NULL, 0);
                }

                Sleep(66);
                second = second - 100.0 / 1000;
                minute =int(second / 60);
                cout << "祝老妈2018年母亲节快乐!" << endl;
                cout << "\t\t\t\t\t\t\t\t\t\t\t致我最最爱的妈妈!-------儿子" << endl<<endl<<endl;
                printf("\t\t\t\t\t\t\t\t\t\t还剩%d分钟哦!请耐心等待,末尾有彩蛋!\n",minute);
        }

        system("cls");//清屏

        for (int i = 0; i < 10; i++)
        {
                COORD coord = { 50,10 };
                SetConsoleCursorPosition(o, coord);
                printf("%d秒后,惊喜即将出现!\n", 10-i);
                Sleep(1000);
        }

        COORD coord = { 0,0 };
        SetConsoleCursorPosition(o, coord);


        for (int i = 0; i < 10; i++)
        {
                cout << "ooooooooooooooooooooo\t\t\t\t\t\t\tooooo\t\t\tooooo" << endl;
                cout << "ooooooooooooooooooooo\t\t\t\t\t\t\tooooo\t\t\tooooo" << endl;
                cout << "ooooooooooooooooooooo\t\t\t\t\t\t\tooooo\t\t\tooooo" << endl;
                cout << "      oooooo                                                            ooooo                   ooooo" << endl;
                cout << "      oooooo                                                            ooooo                   ooooo" << endl;
                cout << "      oooooo                                                            ooooo                   ooooo" << endl;
                cout << "      oooooo                                                            ooooo                   ooooo" << endl;
                cout << "      oooooo                                                            ooooo                   ooooo" << endl;
                cout << "      oooooo                                                            ooooo                   ooooo" << endl;
                cout << "      oooooo                                                            ooooo                   ooooo" << endl;
                cout << "      oooooo                                                            ooooo                   ooooo" << endl;
                cout << "      oooooo                                                            ooooo                   ooooo" << endl;
                cout << "      oooooo                                                            ooooo                   ooooo" << endl;
                cout << "      oooooo                                                            ooooo                   ooooo" << endl;
                cout << "      oooooo                                                            ooooo                   ooooo" << endl;
                cout << "      oooooo                                                            ooooo                   ooooo" << endl;
                cout << "      oooooo                                                            ooooo                   ooooo" << endl;
                cout << "      oooooo                                                            ooooo                   ooooo" << endl;
                cout << "      oooooo                                                            ooooo                   ooooo" << endl;
                cout << "      oooooo                                                            ooooo                   ooooo" << endl;
                cout << "      oooooo                                                            ooooo                   ooooo" << endl;
                cout << "      oooooo                                                            ooooo                   ooooo" << endl;
                cout << "      oooooo                                                            ooooo                   ooooo" << endl;
                cout << "ooooooooooooooooooooo                                    \t\t oooo                   oooo" << endl;
                cout << "ooooooooooooooooooooo                                    \t\tooo                   ooo" << endl;
                cout << "ooooooooooooooooooooo                                       \t\t   ooooooooooooooooooo" << endl;
               
                Sleep(1000);
                coord.X = 0;
                coord.Y = 0;
                SetConsoleCursorPosition(o, coord);
                for (float y = 1.5f; y > -1.5f; y -= 0.1f) {

                        for (float x = -1.5f; x < 1.5f; x += 0.05f) {

                                float a = x * x + y * y - 1;

                                putchar(a * a * a - x * x * y * y * y <= 0.0f ? '*' : ' ');

                        }
                        putchar('\n');
                        Sleep(33);
                }
                Sleep(1000);
                system("cls");
                if (i == 3)
                {
                        mciSendString(TEXT("stop mymusic"), NULL, 0, NULL);
                        system(".\\2.mp4");
                }
        }

        return 0;
}

源码上传,资源文件请通过百度云下载,在win7和win10上运行正常!祝全天下母亲母亲节快乐!!
链接: https://pan.baidu.com/s/1t8HoTq3DWJks6CIkJAkOEQ 密码: f2gp

likesunshine 发表于 2018-5-13 14:41:50

新手问下需要用Visual studio运行吗,还有别的方法没

Sj中国智造 发表于 2018-5-13 14:50:02

本帖最后由 Sj中国智造 于 2018-5-13 15:18 编辑

likesunshine 发表于 2018-5-13 14:41
新手问下需要用Visual studio运行吗,还有别的方法没

windows这个库本来就是微软的,其他的支持不是很好,你可以装vc2010学习版,很小,而且其实我也是新手,我很早就开始用vs2017,不得不说vs2017的确很强大,只需三分钟,你就会爱上这款软件
页: [1]
查看完整版本: 2018献给母亲的礼物