Print many multilines strings at the same place

I’d like to make a little animation in a console app and to do this, I’ve created a ascii art:

                                   ______
                       ,.:b-'::'     ,`::-/,._
                  _.\,,-/` /| |     ,' .`| ,_: ,.
               ` -_,'[ ._-|/,'Y      ` `  /  -/,-.:`.
             ,'/[(o _.. _,".`':| ___  ::/|.`][,'/,,/,'`.
           `:--. `','`,-' [:_,.....'__ ^..,|-.'-  ,, :.
         ,'--.` _ `[.-  --'             '-..`'-['' .L-",`.
       ,L< ':],, ,` ,-                       '- , .''Y"-'.-'`
     _'_,::''/-]._,'        _ ..     .._         `.`]'. -,-:,^.
    _'/,[``.-'/'-       _ :].-''`'''''--.[         -.  .|/:L:| 
    '[' ]>] ' /'       _,'                `-  .      ``'` ,u[<L'
   /,`.  [-' /        ,`                    ,. `.     `.`,,``..| |
  P.P.`[o'),      ,''`__-.                 ,' /',      .'( ; .:]
 /`/  `  .'/XXX  `,'    . -.             ,' ,'   `.       .>  :,`
 | .u[/'|X   X/'      'v ^,         ,' ,'             `^/:.-, |
.:-<.. [||/ XXX '/         ` `     ,' /'         .     || ]::`.'
| |::>,-b|     ||            ^. '---' ,'           Y|     || [./.'/
| /_,[| ||     ||              | ,.  /             ||     || |> --||
Y=]L__`=[|     ||              | ,-  '             ||     | ::_,==:
| |i .| |'.                 /' ,..._ `'           ||     || /L. ,
|_]L,.'-] |     [         ,- ,'     ,' '.         ||     'P..L, / |
 v...-L \     `/.      ,' ,'         `. -_      /      /|'Y-.`::'
   -:,'..,     `  _,' /'             ^,      /,        .[-` ,'
  )_  '   '.     `[`,  /'                 `.',''       /`..:-  |
   <`...,`./ `      `[.=                    `= /        ,_/-/.` ''
    `[,-'.v'`.      ".`._               _.:'         '-' '.>/ '
      [,_,L!`, [`       '  `-...______.,-'           v /'''|]:.'
      `` //'. .`.`.         ' --- -- ''          ',-|' '  b''
       `.Yv-]-, ',-.'-                          ,-''' [,.-,'
         `['./,L|'`.],..  .__           _    ,.',. .[ ]'v']
           `v-/|  <." ..`-.. ::_   |: ,.-\',.'-  ' '','
             `.:`[/   / ' > .:',.||::_|/--'. ``, '/: '
                -',:.`[| .'/,[/ L',]   ^  /``,] ``-`
                    -|, -,: |`-|||/ |``.,..`_,-'
                       ''--.' ==='|::::'-''

(Yeah, it’s a roulette)

I created the same ascii arts with the ball in different positions (like also the cross on the roulette).

My problem is, I think, quite tricky: I’d like to print the roulette to the console something like 4 times per second (maybe more, do not exactly know) at the same place in order that it’s looks like a gif :). I’ve no problem to load the files (and transform them to string) but I didn’t find a way to rewrite at the same place (the “r” won’t work for multiline text).

It would be great, if I could do it without using any library like curses (although I’m a big fan of ncurses in Python!).

Answer

I think curses or something like it is going to be necessary.

As I remember it (curses was a long time ago), there were two points to curses — different terminals, and efficiency on slow terminal connections. You’re going to face both problems, depending on how terminals are connected and how often you end up wanting to repaint the screen.

Curses analyzed the desired output to determine the most efficient way to draw stuff — should it position the cursor three times and draw things separately, or output multiple lines and just draw them once? And what were the character sequences necessary to position the cursor?

Good luck with it, regardless.

Leave a Reply

Your email address will not be published. Required fields are marked *