1dpong.c - src - toys - clsr.net

#include <stdio.h>
#include <sys/select.h>

#define WIDTH 23

int main(void)
{
	int i, j, pos;
	struct timeval tv;

	for(i=0; ; ++i) {
		pos = i % (WIDTH*2-2);
		if (pos > WIDTH-1) {
			pos = 2*WIDTH - pos - 2;
		}
		putchar('\r');
		putchar(']');
		for (j=0; j<WIDTH; ++j) {
			if (j == pos) {
				putchar('O');
			} else if (j == WIDTH/2) {
				putchar('|');
			} else {
				putchar('-');
			}
		}
		putchar('[');

		tv.tv_sec = 0;
		tv.tv_usec = 100000;
		fflush(stdout);
		select(0, NULL, NULL, NULL, &tv);
	}

	return 0;
}