
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.




to rotate.left :thing
  output lput first :thing butfirst :thing
end
to rotate.right :thing
  output fput last :thing butlast :thing
end
 
make "text "|Hello World! |
make "right? "true
 
to step.animation
  label :text			; graphical
  ; type char 13  type :text	; textual
  wait 6			; 1/10 second
  if button <> 0 [make "right? not :right?]
  make "text ifelse :right? [rotate.right :text] [rotate.left :text]
end
 
hideturtle
until [key?] [step.animation]