24h購物| | PChome| 登入
2012-07-01 21:40:28| 人氣727| 回應0 | 上一篇 | 下一篇

[C/C++] Text Animation

推薦 0 收藏 0 轉貼0 訂閱站台

Demo影片: http://youtu.be/0XqR-6YEICU

一時興起打的 CODE

#include <stdio.h>

#include <string.h>
#include <windows.h>
HANDLE hIn, hOut;
void gotoxy (int x, int y) {
    static COORD c; c.X = y; c.Y = x;
    SetConsoleCursorPosition (hOut, c);
}
void showText(int row, char text[], int len) {
    int i, j, wait  = 5;
    for(i = len-1; i >= 0; i--) {
        wait = 250/(i+1);
        if(text[i] == ' ')
            continue;
        for(j = 0; j <= i; j++) {
            gotoxy(row, j);
            putchar(' ');
            gotoxy(row, j+1);
            putchar(text[i]);
            Sleep(wait);
        }
    }
    Sleep(100);
}
int main() {
    hOut = GetStdHandle (STD_OUTPUT_HANDLE);
    hIn  = GetStdHandle (STD_INPUT_HANDLE);
    HANDLE err = INVALID_HANDLE_VALUE;
    char song[][100] = {
        "I walked ten thousnad miles, ten thousands miles to reach you",
        "   And every gasp of breath, I grabbed it just to find you",
        "           I climbed up every hill to get to you",
        "         I wandered ancient lands to hold just you",
        "",
        "          And every single step of the way, I paid",
        "        Every single night and day I searched for you",
        "      Through sand storms and hazy dawns I reached for you"
    };
    int i;
    for(i = 0; i < 8; i++) {
        showText(i, song[i], strlen(song[i]));
    }
    puts("");
    return 0;
}

台長: Morris
人氣(727) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: 亂糟糟筆記 |
此分類下一篇:[資料結構][作業] STACK 實作
此分類上一篇:[名詞學習] 可能有誤

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文