📜  Python|显示“GeeksForGeeks”的动画横幅

📅  最后修改于: 2022-05-13 01:54:38.854000             🧑  作者: Mango

Python|显示“GeeksForGeeks”的动画横幅

想要花哨并创建动画横幅吗?这个程序将在Python控制台打印一个很酷的动画横幅。最初,它仅适用于显示'GeeksForGeeks' 。通过自己添加更多字符将其视为挑战。

重要提示:- 为此,您必须在控制台中打开文件,而不是通过编辑器/IDLE。

Python实现:

import os
import time
  
#You can change the width of the display according to your wish.
WIDTH = 250
  
# Written below currently is GeeksForGeeks. If you wish to get more
# written, you have to add each alphabet manually.
message = "geeksforgeeks".upper()
  
#The message will get printed here.
printedMessage = [ "","","","","","","","","","","","","","", ]
  
"""
What we have done here is a dictionary mapping the letters to their line.
These mapped indexes identify itself to each letter in the dictionary and 
also for each line in the display.
"""
characters = { " " : [ " ",
                       " ",
                       " ",
                       " ",
                       " ",
                       " ",
                       " " ],
  
               "E" : [ "*****",
                       "*    ",
                       "*    ",
                       "*****",
                       "*    ",
                       "*    ",
                       "*****" ],
  
               "O" : [ "*****",
                       "*   *",
                       "*   *",
                       "*   *",
                       "*   *",
                       "*   *",
                       "*****" ],
                 
               "K" : [ " *   *",
                       " *  * ",
                       " * *  ",
                       " **   ",
                       " * *  ",
                       " *  * ",
                       " *   *" ],
                 
               "S" : ["  **** ",
                       " *     ",
                       " *     ",
                       "  ***  ",
                       "     * ",
                       "     * ",
                       " ****  " ],
  
                 
               "G" : [" ***  ",
                       "*   * ",
                       "*     ",
                       "* *** ",
                       "*   * ",
                       "*   * ",
                       " ***  " ],
  
  
               "F" : ["***** ",
                       "*     ",
                       "*     ",
                       "****  ",
                       "*     ",
                       "*     ",
                       "*     " ],
  
               "R" : [" ****  ",
                      " *   * ",
                      " *   * ",
                      " ****  ",
                      " * *   ",
                      " *  *  ",
                      " *   * " ]
                                                                            
                                              
               }
  
  
for row in range(7):
    for char in message:
        printedMessage[row] += (str(characters[char][row]) + "  ")
  
offset = WIDTH
while True:
    os.system("cls")
  
    for row in range(7):
        print(" " * offset + printedMessage[row][max(0,offset*-1):WIDTH - offset])
  
    offset -=1
  
    if offset <= ((len(message)+2)*6) * -1:
        offset = WIDTH
  
    #Use this to change the speed of the animation that you wish to keep.
    time.sleep(0.10)

输出(原始输出将从右向左移动。基本上,它是一个动画。):
有组织的文件夹