逛GitHub时经常可以看到,很多项目README文件中的项目名称都是由特殊的字符拼接而成。不同项目之间所用字体、颜色方面各有差异,视觉上还觉得挺酷炫的,心想这些人不但项目写的好还有闲情逸致的拼字符玩。当然我自己也动手尝试过拼出一些字母,但发现特别耗费时间且效果极差,最后心态就崩了。后来发现那些艺术字体并不是手工拼出来的,有些网站可以自动生成,最近刚好写完毕设闲的无聊就想着自己实现一个,在收集艺术字体方面资料时看到已经有人写了一些操控字体方面的库,在此基础上text2art项目就诞生了。
text2art是在pyfiglet项目基础上用python3实现的库,它的效果看起来像下面那样,可以控制输出字体的样式、颜色、背景、属性和宽度。
('-. .-. ('-.
( OO ) / _( OO)
,--. ,--.(,------.,--. ,--. .-'),-----.
| | | | | .---'| |.-') | |.-') ( OO' .-. '
| .| | | | | | OO ) | | OO )/ | | | |
| |(| '--. | |`-' | | |`-' |\_) | |\| |
| .-. | | .--'(| '---.'(| '---.' \ | | | |
| | | | | `---.| | | | `' '-' '
`--' `--' `------'`------' `------' `-----'
text2art已经上传到PyPi,所以如果你安装了python3那么就可以pip安装
>>> pip install text2art
也可以clone源码安装,Github地址
>>> git clone git@github.com:Fenghuapiao/text2art.git
>>> cd text2art
>>> python setup.py install
查看帮助
>>> text2art h
Usage:
text2art lf # Random display of 25 fonts
text2art rd text [--on_color] [--attr] [--width] [--justify]
text2art gt text [--font] [--color] [--on_color] [--attr] [--width] [--justify]
available text colors:
red, green, yellow, blue, magenta, cyan, white.
available text highlights:
on_red, on_green, on_yellow, on_blue, on_magenta,
on_cyan,on_white.
available attributes:
bold, dark, underline, blink, reverse, concealed.
width: Setting the size of the terminal output font,type is int.
justify: Setting the location of the terminal output font.
available parameter: left, enter, right.
生成随机字体和随机颜色
>>> text2art rd yang
/
Y88b / /~~~8e 888-~88e e88~88e
Y888/ 88b 888 888 888 888
Y8/ e88~-888 888 888 "88_88"
Y C888 888 888 888 /
/ "88_-888 888 888 Cb
_/ Y8""8D
随机显示25种支持的艺术字体(总字体太多,有521种)
>>> text2art lf
生成给定字体类型的艺术字体
>>> text2art gt hang --color cyan
>>> text2art gt hang --color red
调整输出艺术字体的相关属性
>>> text2art gt hang
>>> text2art gt hang --attr bold
设置输出背景颜色
>>> text2art gt hang --on_color on_cyan --color yellow --attr bold
调整输出艺术字体的位置
>>> text2art gt feng --color cyan # default center
>>> text2art gt feng --color cyan --justify left
调整终端输出背景的宽度
>>> text2art gt suibianshu # default width is 80
>>> text2art gt suibianshu --width 120
还有一些小问题在win10的dos中显示调用了colorama的init函数,如何在不调用附加包的情况下实现?
fire库如何友好的输出帮助信息?
最后
非常欢迎大家star和fork, 由于时间匆忙代码可能存在未知的bug,由于艺术字体种类太多本人并没有一一测试,对有哪些好看的字体或者配色方案并不了解,也希望大家在使用过程中(如果有人用的话)能够在issue给予反馈非常感谢。
更多有趣的回答见,可以用 Python 编程语言做哪些神奇好玩的事情?可以用 Python 编程语言做哪些神奇好玩的事情?