
Animation is integral to many parts of GUIs, including both the fancy effects when things change used in window managers, and of course games.   The core of any animation system is a scheme for periodically changing the display while still remaining responsive to the user.   This task demonstrates this.



Task

Create a window containing the string "Hello World! " (the trailing space is significant).

Make the text appear to be rotating right by periodically removing one letter from the end of the string and attaching it to the front.

When the user clicks on the (windowed) text, it should reverse its direction.




DIM C AS STRING = "Hello World! ", SIZE AS USHORT = LEN(C)
DIM DIRECTION AS BYTE = 0
DIM AS INTEGER X, Y, BTNS
DIM HELD AS BYTE = 0
 
SCREEN 19
 
DO
 LOCATE 1, 1
 PRINT C
 
 GETMOUSE X, Y, , BTNS
 
 IF BTNS <> 0 AND HELD = 0 THEN
  'remember if it was pressed, to not react every frame
  HELD = 1
  IF X >= 0 AND X < SIZE * 8 AND Y >= 0 AND Y < 16 THEN
   DIRECTION = 1 - DIRECTION
  END IF
 ELSE
  HELD = 0
 END IF
 
 IF INKEY = CHR(255) + CHR(107) THEN EXIT DO
 
 IF DIRECTION = 0 THEN
  C = RIGHT(C, 1) + LEFT(C, SIZE - 1)
 ELSE
  C = RIGHT(C, SIZE - 1) + LEFT(C, 1)
 END IF
 
 SLEEP 100, 1
LOOP