鱼C论坛

 找回密码
 立即注册
查看: 3026|回复: 2

[技术交流] 2018献给母亲的礼物

[复制链接]
发表于 2018-5-13 13:51:57 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 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[25][80] = { _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[sy++][0];
                        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[sy], 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\t  ooo                   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
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-5-13 14:41:50 | 显示全部楼层
新手问下需要用Visual studio运行吗,还有别的方法没
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-5-13 14:50:02 | 显示全部楼层
本帖最后由 Sj中国智造 于 2018-5-13 15:18 编辑
likesunshine 发表于 2018-5-13 14:41
新手问下需要用Visual studio运行吗,还有别的方法没


windows这个库本来就是微软的,其他的支持不是很好,你可以装vc2010学习版,很小,而且其实我也是新手,我很早就开始用vs2017,不得不说vs2017的确很强大,只需三分钟,你就会爱上这款软件
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-1 23:42

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表