美文网首页
数字瀑布

数字瀑布

作者: Jingtianer | 来源:发表于2019-03-14 20:09 被阅读0次

马上要到五四述职了,班长想做一个类似黑客帝国的代码流,经过一上午的百度,终于东拼西凑出了这份代码

运行环境

项目 信息
编译环境 visual studio 2017
测试平台 windows 10 (x64)
CPU Intel(R) Core(TM) i5-7300HQ
内存 8GB

代码

#include "pch.h"
#include <Windows.h>
#include <fstream>
#include <iostream>
#include <stdarg.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
HANDLE handle = []() { return GetStdHandle(STD_OUTPUT_HANDLE); }();
typedef struct
{
    int x, y;
    char ch;
} STU;
STU st[100];
//出现位置

void gotoxy(int x, int y)
{
    HANDLE hout;
    COORD pos;
    pos.X = x;
    pos.Y = y;

    hout = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleCursorPosition(hout, pos);
}

/*隐藏光标*/
void show_cursor(int hide)
{
    CONSOLE_CURSOR_INFO cciCursor;
    HANDLE hout;

    hout = GetStdHandle(STD_OUTPUT_HANDLE);
    if (GetConsoleCursorInfo(hout, &cciCursor))
    {
        cciCursor.bVisible = hide;
        SetConsoleCursorInfo(hout, &cciCursor);
    }
}

/*设置颜色*/
void set_color(int color)
{
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
}
void full_screen()
{
    HWND hwnd = GetForegroundWindow();
    int cx = GetSystemMetrics(SM_CXSCREEN);                              /* 屏幕宽度 像素 */
    int cy = GetSystemMetrics(SM_CYSCREEN);                              /* 屏幕高度 像素 */
    LONG l_WinStyle = GetWindowLong(hwnd, GWL_STYLE); /* 获取窗口信息 */ /* 设置窗口信息 最大化 取消标题栏及边框 */
    SetWindowLong(hwnd, GWL_STYLE, (l_WinStyle | WS_POPUP | WS_MAXIMIZE) & ~WS_CAPTION & ~WS_THICKFRAME & ~WS_BORDER);
    SetWindowPos(hwnd, HWND_TOP, 0, 0, cx, cy, 0);
}
void cprintf(char str, WORD color)
{
    //setFont(size);

    Sleep(200);

    WORD colorOld;
    HANDLE handle = ::GetStdHandle(STD_OUTPUT_HANDLE);

    CONSOLE_SCREEN_BUFFER_INFO csbi;
    GetConsoleScreenBufferInfo(handle, &csbi);
    colorOld = csbi.wAttributes;
    SetConsoleTextAttribute(handle, color);
    cout << str;
    SetConsoleTextAttribute(handle, colorOld);
}
void setFont(int size)
{
    COORD FontSize = { size, size * 2 };
    CONSOLE_FONT_INFOEX font = { 0 };
    GetCurrentConsoleFontEx(handle, true, &font);
    font.dwFontSize = FontSize;
    font.cbSize = sizeof(CONSOLE_FONT_INFOEX);
    SetCurrentConsoleFontEx(handle, true, &font);
}
int main()
{
    full_screen();
    system("pause");
    system("cls");

    setFont(45);
    string str = "Welcome to CS 1802\n";
    for (int i = 0; i < str.length(); i++)
    {
        cprintf(str[i], 2);
    }
    system("color");
    system("cls");
    setFont(35);

    int i, j;
    show_cursor(0);
    srand(time(NULL));
    //初始化结构体
    for (i = 0; i < 100; i++)
    {
        st[i].x = rand() % 80;
        st[i].y = rand() % 20;
        st[i].ch = rand() % (49 - 47) + 48;
    }
    while (1)
    {
        for (i = 0; i < 100; i++)
        {
            gotoxy(st[i].x, st[i].y);
            set_color(0x2);
            putchar(st[i].ch);
            gotoxy(st[i].x, st[i].y - 5);
            putchar(' ');
            st[i].y++;
            st[i].ch = rand() % (49 - 47) + 48;
            if (st[i].y - 5 >= 18)
            {
                gotoxy(st[i].x, st[i].y - 1);
                putchar(' ');
                gotoxy(st[i].x, st[i].y - 2);
                putchar(' ');
                gotoxy(st[i].x, st[i].y - 3);
                putchar(' ');
                gotoxy(st[i].x, st[i].y - 4);
                putchar(' ');
                gotoxy(st[i].x, st[i].y - 4);
                putchar(' ');
            }
            if (st[i].y > 23)
            {
                st[i].x = rand() % 80;
                st[i].y = rand() % 20;
            }
            gotoxy(st[i].x, st[i].y);
            set_color(0xA);
            putchar(st[i].ch);
        }
        Sleep(120);
    }
    return 0;
}

来源

c语言实现数字雨

C++控制台输出彩色文字

今日收获

  1. 学会了c/c++下的可变参数写法,不知道能不能自己实现一个printf。
  2. 没了hhh,我大概就是那种只需要ctrl c v三个键的程序员吧...

相关文章

  • 数字瀑布

    马上要到五四述职了,班长想做一个类似黑客帝国的代码流,经过一上午的百度,终于东拼西凑出了这份代码 运行环境 代码 ...

  • 韭菜是割不完的

    最近数字货币领域又来了一大波瀑布,有事一堆新闻报道数字货币崩盘,比特币瀑布。历史总是惊人的相似,比特币被报道无数次...

  • 是时候学点儿区块链应用开发了

    数字货币从年初开始就一路下跌,不断的瀑布瀑布再瀑布。区块链的势头却越发强劲,对区块链技术人才的需求也成爆发性增长。...

  • 瀑布流布局与木桶布局

    瀑布流布局 在瀑布流布局中,每一个元素的宽度相同,高度不同,下图中的数字表示图片被添加的顺序,每次添加新的图片时,...

  • 怎样在币市长熊和瀑布中活下来?

    在币市长熊和瀑布中怎样活下来 今天和大家分享一些实战中的经验,比如怎么样在技术面去操作投资数字资产,应对瀑布和熊市...

  • 2018全球数字货币最具投资价值TOP10

    币圈萌新不知如何进场,比特币这波瀑布到底该抛吗? 如今数字货币在投资市场大火,在全球经济趋势的发展下,数字货币已成...

  • 9.4投资_别人贪婪我恐惧,别人恐惧我贪婪。

    9月4日,国家对数字货币执行监管,经历了 各种数字货币 瀑布般的下跌,感受到了币圈 巨大的恐怖,而自己也深深的陷入...

  • 全球最震撼的“海底瀑布”,落差高达3500米,现实中的3D壁纸!

    相信很多旅游爱好者都参观过壮观的瀑布,我国著名的瀑布有黄果树瀑布、壶口瀑布、赤水瀑布、德天瀑布等等,这些瀑布都位于...

  • 2018-06-27 优选糖果-SEED、TELE、RUNS

    这一段数字货币市场一个瀑布接着一个瀑布,再加上世界杯,优质空投真的是不容易找呀,还好阿根廷出线了,今天更新两个空投...

  • 瀑布啊瀑布

    EOS今天一直盘桓在56块。 想我1.12晚上入场,第一个买的就是它,102元,睡了一夜涨到133元。 只好补仓了...

网友评论

      本文标题:数字瀑布

      本文链接:https://www.haomeiwen.com/subject/zgfhmqtx.html