Created
October 21, 2017 08:53
-
-
Save rerrahkr/96121adc69b63b53022ce184c9803800 to your computer and use it in GitHub Desktop.
ncursesを使った遊び(文字でアニメーション)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
#include <ncurses.h> | |
#define MOJI ">>WAIT>-> >" | |
#define YOKOHABA 73 | |
#define HAYASA 0.015 | |
#define SA 2 | |
int main() | |
{ | |
double asobi[9]; | |
int i; | |
int cnt=0, rollflag=0; | |
double r=0, g=0, b=0; | |
int rflag=0, gflag=0, bflag=0; | |
initscr(); | |
curs_set(0); | |
cbreak(); | |
noecho(); | |
cbreak(); | |
start_color(); | |
init_color(COLOR_BLUE, 443, 470, 1000); | |
init_pair(1, COLOR_BLUE, COLOR_BLACK); | |
init_pair(2, COLOR_RED, COLOR_BLACK); | |
for (i=0; i<9; i++) { | |
asobi[i] = i * SA; | |
} | |
while (1) { | |
clear(); | |
attron(COLOR_PAIR(1)); | |
mvaddstr( 0, 0, "|> waiting for oppornent."); | |
mvaddstr( 1, 0, "|> please stand by"); | |
switch (rollflag) { | |
case 0: | |
mvaddstr(1,18, ""); | |
break; | |
case 1: | |
mvaddstr(1,18, "."); | |
break; | |
case 2: | |
mvaddstr(1,18, ".."); | |
break; | |
case 3: | |
mvaddstr(1,18, "..."); | |
break; | |
} | |
if (cnt < 1000) { | |
mvaddstr(1,30, "|"); | |
} else if (1000 <= cnt && cnt < 2000) { | |
mvaddstr(1,30, "\\"); | |
} else if (2000 <= cnt && cnt < 3000) { | |
mvaddstr(1,30, "-"); | |
} else if (3000 <= cnt) { | |
mvaddstr(1,30, "/"); | |
} | |
cnt++; | |
cnt %= 4000; | |
if (cnt == 0) { | |
rollflag++; | |
rollflag %= 4; | |
} | |
init_color(COLOR_RED, (int)r, (int)g, (int)b); | |
attron(COLOR_PAIR(2)); | |
for (i=0; i<9; i++) { | |
mvaddstr( 4+i, (int)asobi[i], MOJI); | |
mvaddstr(20-i, (int)asobi[i], MOJI); | |
asobi[i] += HAYASA; | |
asobi[i] = fmod(asobi[i], YOKOHABA); | |
} | |
if (r >= 1000) rflag = 1; else if (r <= 0) rflag = 0; | |
if (g >= 1000) gflag = 1; else if (g <= 0) gflag = 0; | |
if (b >= 1000) bflag = 1; else if (b <= 0) bflag = 0; | |
if (rflag == 0) r += 0.125; else r -= 0.5; | |
if (gflag == 0) g += 0.25; else g -= 0.125; | |
if (bflag == 0) b += 0.3; else b -= 0.25; | |
// attroff(COLOR_PAIR(1)); | |
refresh(); | |
} | |
endwin(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment