在控制台中打印多行ASCII动画 [英] Printing multiline ASCII animation in the console

查看:84
本文介绍了在控制台中打印多行ASCII动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在控制台应用程序中制作一个小动画,并且为此,我创建了ASCII艺术作品:

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

(是的,是轮盘赌)

我用不同位置的球(也就是轮盘上的十字)创造了相同的ASCII艺术.

我的问题是,我认为这很棘手:我想在同一位置将轮盘赌每秒打印到控制台上,例如每秒4次(可能更多,不完全知道),以便看起来像gif.我加载文件并将其转换为字符串没有问题,但是我没有找到在同一位置重写的方法( \ r 不适用于多行文本)./p>

如果我不用使用curses之类的库就可以做到(虽然我是Python中ncurses的忠实拥护者!).

解决方案

我认为诅咒或类似的东西将是必要的.

正如我所记得的(诅咒是很久以前的)了,诅咒有两点:不同的终端,以及低速终端连接的效率.您将要面对两个问题,具体取决于终端的连接方式以及最终想要重新粉刷屏幕的频率.

Curses分析了所需的输出,以确定最有效的绘图方法-它应该将光标定位3次并分别进行绘制,还是输出多行并仅绘制一次?定位光标所需的字符序列是什么?

祝你好运

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!).

解决方案

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.

这篇关于在控制台中打印多行ASCII动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆