본문 바로가기

IT

bounced1d.c

// set_ticker.c 파일과 함께 컴파일 해야 합니다.

// gcc bounced1d.c set_ticker.c -o -lcurses bounce1d


#include <stdio.h>

#include <curses.h>

#include <signal.h>


#define MESSAGE "hello"

#define BLANK " "


int row;

int col;

int dir;


int main()

{

int delay;

int ndelay;

int c;

void move_msg(int);

initscr();

crmode();

noecho();

clear();


row = 10;

col = 0;

dir = 1;

delay = 200;


move(row,col);

addstr(MESSAGE);

signal(SIGALRM, move_msg);

set_ticker(delay);


while(1)

{

ndelay = 0;

c = getch();

if(c=='Q') break;

if(c==' ') dir = -dir;

if(c=='f' && delay > 2) ndelay = delay/2;

if(c=='s') ndelay = delay *2;

if(ndelay >0)

set_ticker(delay = ndelay);

}


endwin();

return 0;

}


void move_msg(int signum)

{

signal(SIGALRM, move_msg);

move(row, col);

addstr(BLANK);

col += dir;

move(row,col);

addstr(MESSAGE);

refresh();


if(dir == -1 && col <= 0)

dir = 1;

else if (dir ==1 && col +strlen(MESSAGE) >= COLS)

dir = -1;

}



'IT' 카테고리의 다른 글

exec1.c  (0) 2014.11.11
set_ticker.c  (0) 2014.11.05
sigactdemo2.c  (0) 2014.11.05
sigactdemo.c  (0) 2014.11.05
sigdemo3.c  (0) 2014.11.05