
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.




str$="Hello, World! "
direction=0	#value of 0: to the right, 1: to the left.
tlx=10		#Top left x
tly=10		#Top left y
fastgraphics
font "Arial",20,100	#The Font configuration (Font face, size, weight)
 
main:
while clickb=0
	if direction=0 then
		str$=RIGHT(str$,1) + LEFT(str$,length(str$)-1)
	else
		str$=MID(str$,2,length(str$)-1)+LEFT(str$,1)
	end if
	refresh
	clg
	color red
	text tlx,tly,str$
	pause .1
end while
	#Note: textheight() and textwidth() depends on the latest configuration of the FONT command.
if clickb=1 and clickx>=tlx and clickx<=tlx+textwidth(str$) and clicky>=tly and clicky<=tly+textheight() then
	direction=NOT direction
end if
clickclear
goto main