2009年11月30日 星期一

文字特效

 
複習完 Matrix 後突然想寫這個,花了 15 分鐘...
#include <windows.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>

int main (/* daviddr 091129 */)
{
    const int   W = 80, H = 24, L = 12;
    const float PL = 2.5; 
    float pos[W], step[W];
    int x, y, c;
    char  s[] = " ";

    srand (time(0));
    SetConsoleTitle (L"Art");
    HDC hdc = GetDC (FindWindow (0, L"Art")); 
    SetBkColor (hdc,0);
 
    for (x=0; x<W; ++x) {
        pos [x] = rand() % int(H*PL);
        step[x] = float (rand() % 7 + 5) / 5;
    }
    for (;;Sleep(120))
        for (x=0; x<W; ++x ) {
            for (y=0; y<H; ++y) {
                c  = int (pos[x]) - y;
                c  = ((0<c && c<L)? 255-c*255/L: 0);
                *s = 33 + rand() % 93;
                SetTextColor (hdc, c>225? 0xFFFFFF: RGB(0,c,0));   
                TextOutA (hdc, x*8, y*16, s, 1);
            }
            pos[x] += step[x];
            if (pos[x] >= H*PL) {
                pos[x] = 0;
                step[x] = float (rand() % 7 + 5) / 5;
            }
        }
}
截圖:

沒有留言:

張貼留言