Text Animation

F

Fazer

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
 
J

Josiah Carlson

Fazer said:
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


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
 
G

Gordon Airport

Fazer wrote:

snip
> Or maybe even
a rotating " | " that I have seen before in some installation
programs.

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.
 
A

Andrew Henshaw

Fazer said:
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

I use this:

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

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

def __call__(self):
sys.stdout.write(Spinner.SYMBOLS[self.index]+'\b')
self.index = (self.index+1) % len(Spinner.SYMBOLS)

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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top