
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.




include c:\cxpl\codes;
int     CpuReg, Dir, I, J;
char    Str;
string  0;                      \use zero-terminated strings, instead of MSb set
[CpuReg:= GetReg;               \provides access to 8086 CPU registers
\      0123456789012
Str:= "Hello World! ";
Clear;
Dir:= -1;                       \make string initially scroll to the right
I:= 0;                          \index to start of displayed portion of string
repeat  Cursor(0, 0);           \set cursor position to upper-left corner
        for J:= 0 to 12 do
                [ChOut(0, Str(I));  I:= I+1;  if I>12 then I:= 0];
        Sound(0, 2, 1);         \delay about 1/9 second
        I:= I+Dir;              \step starting position of displayed string
        if I<0 then I:=12;      \wraparound
        if I>12 then I:= 0;
        CpuReg:= GetReg;        \get mouse button press information
        CpuReg(0):= 5;  CpuReg(1):= 0;
        SoftInt($33);           \reverse direction if left button was pressed
        if CpuReg(1) then Dir:= -Dir;
until   KeyHit;                 \any keystroke terminates program
]