Guest User

Untitled

a guest
Feb 14th, 2017
157
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <ncurses.h>
  2. #include <unistd.h>
  3.  
  4. #define DELAY 35000
  5.  
  6. // terminal stops with d key
  7.  
  8. int main(int argc, char *argv[]) {
  9.   int x = 0,
  10.       y = 0;
  11.  
  12.   int max_x = 0,
  13.       max_y = 0;
  14.  
  15.   int next_x = 0;
  16.  
  17.   int direction = 1;
  18.  
  19.   initscr();
  20.   noecho();
  21.   curs_set(FALSE);
  22.   timeout (0);
  23.  
  24.   getmaxyx(stdscr, max_y, max_x);
  25.  
  26.   x = max_x / 2;
  27.   y = max_y / 2;
  28.  
  29.   char ch;
  30.  
  31.   while (1) {
  32.     getmaxyx(stdscr, max_y, max_x);
  33.  
  34.     y = max_y / 2;
  35.  
  36.     clear();
  37.     mvprintw(y, x, "o");
  38.     refresh();
  39.  
  40.     usleep(DELAY);
  41.  
  42.     next_x = x + direction;
  43.  
  44.     if (next_x >= max_x || next_x < 0) {
  45.       direction*= -1;
  46.     } else {
  47.       x+= direction;
  48.     }
  49.     ch = getch();
  50.     if (ch == 100) {
  51.       break;
  52.     }
  53.    
  54.   }
  55.  
  56.   endwin();
  57.  
  58.   return 0;
  59. }
RAW Paste Data