簡體   English   中英

如何編寫 ASCII 文本代碼,我不需要像 pyfiglet 那樣導入,而是手動執行並使用我在 python 中選擇的任何字符

[英]How do I write a code of ASCII text where I do not need to import like pyfiglet but do it manually and use whatever character of my choice in python

如何編寫 ASCII 文本代碼,我不需要像 pyfiglet 那樣導入,而是手動執行並使用我在 python 中選擇的任何字符

我希望我的 output 是:

Hello world

+     + +----  -------
|     | |---|     |
|-----| |      -------

例如/參考:在此處輸入圖像描述

您可以使用您想要的任何字符手動設計字母(可能首先在網格紙上繪制它們),將它們存儲在字典中並編寫一個 function ,該 output 的每一行來自字符的相應行。 手工設計一個完整的 ASCII 字體是一項相當艱巨的工作,但是 function 非常簡單:

def asciiart(letters,word=""):
    art = ""
    for line in range(letters["Size"]):
        for c in word:
            art+=letters[c].split('\n')[line]+" "
        art+="\n"
    return art
            
    

letters = {"Size":5,
           " ": "     \n     \n     \n     \n     ",
           "A": " ### \n#   #\n#####\n#   #\n#   #",
           "C": " ####\n#    \n#    \n#    \n ####"}

print(letters["A"],"\n")
print(letters["C"],"\n")
print(asciiart(letters,"AC CA AA"))

該程序的 output 將是:

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

 ####
#    
#    
#    
 #### 

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM