8-bit style bouncing ball around a canvas Inspired by this listing from the Commodore 64 User's Guide:

10 PRINT "{CLR/HOME}"
20 POKE 53280,7 : POKE 53281,13
30 X = 1 : Y = 1
40 DX = 1 : DY = 1
50 POKE 1024 + X + 40 * Y, 81
60 FOR T = 1 TO 10 : NEXT
70 POKE 1024 + X + 40 * Y, 32
80 X = X + DX
90 IF X &lt;= 0 OR X &gt;= 39 THEN DX = -DX
100 Y = Y + DY
110 IF Y &lt;= 0 OR Y &gt;= 24 THEN DY = -DY
120 GOTO 50


Make a similar program in your chosen language/platform to bounce a ball-alike object around your terminal, screen, canvas or other visual display area.

You don't have to mimic the C64's PETSCII graphics exactly, a simple O or o will do, nor do you have to use the GOTO command if it exists in your language still. As long as your ball starts at the top of your canvas and travels diagonally until it hits a canvas limit, and then bounces accordingly, as follows:


Travelling downwards and right and hits the bottom of the screen area, bounces up and continues right;
Travelling up and right and hits the right-most boundary, and bounces left and up;
Travelling left and up and hits the top, bounces left and down;
Travelling left and down and reaches the left-most boundary, bounces right and down;
Hits any corner and reverses direction;


Then we're all good.

You don't have to move the ball 8-pixels at a time either, like is happening in the BASIC listing on the C64; you can move one character block or one pixel at a time, whichever you think is most appropriate.

To see this BASIC listing working, you can type it in with this online Commodore 64 emulator providing your browser supports Flash.
Bash + Unix utilities, 125 117 bytes

for((x=y=u=v=1;;x+=u,y+=v,u=(x&lt;1||x&gt;=`tput cols`-1)?-u:u,v=(y&lt;1||y&gt;=`tput lines`-1)?-v:v)){
tput cup $y $x
sleep .1
}




Animation of sample run: