#include #include #define MAX_X 100.0 #define MAX_Y 100.0 #define MAX_R 24 #define MAX_C 80 void xy2rc(float x, float y, int *r, int *c) { *c = (x / MAX_X) * MAX_C; *r = MAX_R - ((y / MAX_Y) * MAX_R); } float ball_x = 0.0; float ball_y = 0.0; float dir_x = +2.0; float dir_y = +1.0; void move_ball(float x, float y) { /* Move ball */ ball_x = x; ball_y = y; } void paint_ball() { int r, c; xy2rc(ball_x, ball_y, &r, &c); mvaddch(r, c, ACS_DIAMOND); } void paint() { clear(); paint_ball(); refresh(); } int main() { initscr(); /* Start curses mode */ curs_set(0); /* Disable cursor */ while(true) { ball_x += dir_x; ball_y += dir_y; if (ball_x>MAX_X || ball_x<0) { dir_x = -dir_x; } if (ball_y>MAX_Y || ball_y<0) { dir_y = -dir_y; } paint(); usleep(50000); } refresh(); /* Print it on to the real screen */ getch(); /* Wait for user input */ endwin(); /* End curses mode */ }