
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.




PROC DrawWindow(BYTE x,y,len)
  BYTE i
 
  Position(x,y)
  Put(17)
  FOR i=1 TO len DO Put(18) OD
  Put(5)
 
  Position(x,y+1)
  Put(124)
  Position(x+len+1,y+1)
  Put(124)
 
  Position(x,y+2)
  Put(26)
  FOR i=1 TO len DO Put(18) OD
  Put(3)
RETURN
 
PROC RotateLeft(CHAR ARRAY a)
  BYTE i,tmp
 
  IF a(0)<1 THEN RETURN FI
 
  i=1 tmp=a(i)
  WHILE i<a(0)
  DO
    a(i)=a(i+1)
    i==+1
  OD
  a(a(0))=tmp
RETURN
 
PROC RotateRight(CHAR ARRAY a)
  BYTE i,tmp
 
  IF a(0)<1 THEN RETURN FI
 
  i=a(0) tmp=a(i)
  WHILE i>1
  DO
    a(i)=a(i-1)
    i==-1
  OD
  a(1)=tmp
RETURN
 
PROC Wait(BYTE frames)
  BYTE RTCLOK=$14
 
  frames==+RTCLOK
  WHILE frames#RTCLOK DO OD
RETURN
 
PROC Main()
  BYTE
    CH=$02FC, ;Internal hardware value for last key pressed
    CRSINH=$02F0 ;Controls visibility of cursor
  BYTE k,dir=[0]
  CHAR ARRAY text="Hello World! "
 
  Graphics(0)
  CRSINH=1 ;hide cursor
  Position(4,1)
  PrintE("Press Space to reverse direction")
  Position(11,2)
  Print("Press Esc to exit")
  DrawWindow(12,4,text(0))
 
  DO
    Position(13,5)
    Print(text)
    k=CH CH=$FF
    IF k=33 THEN dir==!$FF FI
    IF dir THEN
      RotateLeft(text)
    ELSE
      RotateRight(text)
    FI
    Wait(6)
  UNTIL k=28
  OD
 
  CRSINH=0 ;show cursor
RETURN