Text Animation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fazer

    Text Animation

    Hello,

    I was wondering if anyone has done any simple text-based animation?

    I mean things such as text-based pre-loaders. One example would be
    when you use the *nix utility called `wget.` You get that fancy "
    ====> " type of animation as you download a large file. Or maybe even
    a rotating " | " that I have seen before in some installation
    programs.

    Any ideas how these effects can be achieved?

    Thanks a lot!

    Faizan
  • Josiah Carlson

    #2
    Re: Text Animation

    Fazer wrote:[color=blue]
    > Hello,
    >
    > I was wondering if anyone has done any simple text-based animation?
    >
    > I mean things such as text-based pre-loaders. One example would be
    > when you use the *nix utility called `wget.` You get that fancy "
    > ====> " type of animation as you download a large file. Or maybe even
    > a rotating " | " that I have seen before in some installation
    > programs.
    >
    > Any ideas how these effects can be achieved?
    >
    > Thanks a lot!
    >
    > Faizan[/color]


    Yeah, don't print linefeed ('\n') characters, only print carriage
    returns ('\r').

    import time
    for i in xrange(75):
    print '*'*i, '\r',
    time.sleep(.1)

    - Josiah

    Comment

    • Gordon Airport

      #3
      Re: Text Animation

      Fazer wrote:

      snip
      [color=blue]
      > Or maybe even
      > a rotating " | " that I have seen before in some installation
      > programs.
      >[/color]

      On each loop use the \b backspace character to move the cursor back,
      then overwrite with progressive characters for the spinner. This can
      look bad if the cursor is visible.

      Comment

      • Skip Montanaro

        #4
        Re: Text Animation


        faizan> Any ideas how these effects can be achieved?

        You can start here:



        That module provides a couple simple progress counters.

        Skip

        Comment

        • Andrew Henshaw

          #5
          Re: Text Animation

          Fazer wrote:
          [color=blue]
          > Hello,
          >
          > I was wondering if anyone has done any simple text-based animation?
          >
          > I mean things such as text-based pre-loaders. One example would be
          > when you use the *nix utility called `wget.` You get that fancy "
          > ====> " type of animation as you download a large file. Or maybe even
          > a rotating " | " that I have seen before in some installation
          > programs.
          >
          > Any ideas how these effects can be achieved?
          >
          > Thanks a lot!
          >
          > Faizan[/color]

          I use this:

          ############### ############### #####
          import sys

          class Spinner:
          SYMBOLS = '|/-\\'
          def __init__(self):
          self.index = 0

          def __call__(self):
          sys.stdout.writ e(Spinner.SYMBO LS[self.index]+'\b')
          self.index = (self.index+1) % len(Spinner.SYM BOLS)

          ############### ############### #####

          And call it like this:

          ############### ############### #####
          if __name__ == '__main__':
          import time

          spin = Spinner()
          for i in range(100):
          spin()
          time.sleep(0.1)
          ############### ############### #####


          This looks fine under the Win2K cmd window; but, as pointed out in another
          reply, you may need to turn off the cursor. I just tested it under Konsole
          on Linux, and the block cursor doesn't allow the effect to show.

          --Andy

          Comment

          Working...