zoukankan      html  css  js  c++  java
  • EasyX—数字雨

     1 /////////////////////////////////////////////////////////////////////
     2 // 程序名称:数字雨
     3 // 编译环境:VC6.0  EasyX
     4 // 作  者:flx413
     5 // 时    间:2016-5-2
     6 /////////////////////////////////////////////////////////////////////
     7 
     8 #include <stdio.h>
     9 #include <windows.h>
    10 #include <graphics.h>
    11 #include <stdlib.h>
    12 #include <time.h>
    13 
    14 #define SCREEN_WIDTH 1366
    15 #define SCREEN_HEIGHT 768
    16 #define DEF_RAIN_NUM 91  //雨的列数
    17 
    18 //数字雨开始的位置
    19 int g_nRainPos[DEF_RAIN_NUM] = { 0 };
    20 
    21 //数字雨的字符串
    22 char g_strRain[DEF_RAIN_NUM][10] = { 0 };
    23 
    24 //随机产生一个字母
    25 char CreateRandomNum() {
    26     char nRandomNum = 0;
    27 
    28     while( 1 ) {
    29         nRandomNum = rand() % 123;   //随机产生0~122的一个字符
    30 
    31         if( ( nRandomNum >= 65 && nRandomNum <= 90 ) || nRandomNum >= 97 ) {
    32             return nRandomNum;
    33         }
    34     }
    35 }
    36 
    37 //随机产生数字雨的开始位置
    38 void InitPos() {
    39     for( int i = 0; i < DEF_RAIN_NUM; i++ ) {
    40         g_nRainPos[i] = rand() % SCREEN_HEIGHT;
    41     }
    42 }
    43 
    44 //初始化数字雨
    45 void InitNumRain() {
    46     for( int i = 0; i < DEF_RAIN_NUM; i++ ) {
    47         for( int j = 0; j < 10; j++ ) {
    48             g_strRain[i][j] = CreateRandomNum();
    49         }
    50     }
    51 }
    52 
    53 //显示雨
    54 void ShowNumRain() {
    55     for( int i = 0; i < DEF_RAIN_NUM; i++ ) {
    56         //设置字体颜色
    57         settextcolor( RGB( 255, 255, 255 ) );  //白色
    58         for( int j = 0; j < 10; j++ ) {
    59             outtextxy( i * 15, g_nRainPos[i] - 15 * j, g_strRain[i][j] );
    60             settextcolor( RGB( 0, 255 - 28 * j, 0 ) );
    61         }
    62     }
    63 
    64     for( i = 0; i < DEF_RAIN_NUM; i++ ) {
    65         g_nRainPos[i] += 15;    //屏幕刷新后雨的位置下降15
    66     }
    67 
    68     for( i = 0; i < DEF_RAIN_NUM; i++ ) {
    69         if( g_nRainPos[i] - 10 * 15 >= SCREEN_HEIGHT ) {
    70             g_nRainPos[i] = 0;
    71         }
    72     }
    73 }
    74 int main() {
    75     srand((unsigned)time(NULL));
    76     initgraph( SCREEN_WIDTH, SCREEN_HEIGHT );
    77     
    78     InitPos();
    79     InitNumRain();
    80     
    81     BeginBatchDraw();
    82 
    83     while( 1 ) {
    84        InitNumRain();
    85        ShowNumRain();  
    86        FlushBatchDraw();
    87        Sleep( 100 );   //延时0.1秒
    88        cleardevice();  //清空屏幕
    89     }
    90 
    91     EndBatchDraw();
    92     closegraph();
    93     return 0;
    94 }

    截图:

  • 相关阅读:
    Codeforces Round #610 (Div. 2)C(贪心,思维)
    Educational Codeforces Round 80 (Rated for Div. 2)C(DP)
    BZOJ2190 仪仗队
    BZOJ3613 南园满地堆轻絮
    BZOJ1084 最大子矩阵
    BZOJ1036 树的统计Count
    BZOJ1452 Count
    BZOJ2242 计算器
    BZOJ2705 Longge的问题
    BZOJ1509 逃学的小孩
  • 原文地址:https://www.cnblogs.com/lzjtdxfxl/p/5452091.html
Copyright © 2011-2022 走看看