使用Python生成ASCII字符画

在很多的网站主页中或者程序的注释中会有一些好看的字符注释画。显得很牛逼的样子

例如:

知乎

         _____                    _____                    _____                    _____
/\ \ /\ \ /\ \ /\ \
/::\____\ /::\ \ /::\ \ /::\ \
/:::/ / \:::\ \ /::::\ \ /::::\ \
/:::/ / \:::\ \ /::::::\ \ /::::::\ \
/:::/ / \:::\ \ /:::/\:::\ \ /:::/\:::\ \
/:::/____/ \:::\ \ /:::/__\:::\ \ /:::/__\:::\ \
/::::\ \ /::::\ \ /::::\ \:::\ \ /::::\ \:::\ \
/::::::\ \ _____ ____ /::::::\ \ /::::::\ \:::\ \ /::::::\ \:::\ \
/:::/\:::\ \ /\ \ /\ \ /:::/\:::\ \ /:::/\:::\ \:::\____\ /:::/\:::\ \:::\ \
/:::/ \:::\ /::\____\/::\ \/:::/ \:::\____\/:::/ \:::\ \:::| |/:::/__\:::\ \:::\____\
\::/ \:::\ /:::/ /\:::\ /:::/ \::/ /\::/ |::::\ /:::|____|\:::\ \:::\ \::/ /
\/____/ \:::\/:::/ / \:::\/:::/ / \/____/ \/____|:::::\/:::/ / \:::\ \:::\ \/____/
\::::::/ / \::::::/ / |:::::::::/ / \:::\ \:::\ \
\::::/ / \::::/____/ |::|\::::/ / \:::\ \:::\____\
/:::/ / \:::\ \ |::| \::/____/ \:::\ \::/ /
/:::/ / \:::\ \ |::| ~| \:::\ \/____/
/:::/ / \:::\ \ |::| | \:::\ \
/:::/ / \:::\____\ \::| | \:::\____\
\::/ / \::/ / \:| | \::/ /
\/____/ \/____/ \|___| \/____/

RESTful

______ _____ _____ _____    __
| ___ \ ___/ ___|_ _| / _| | |
| |_/ / |__ \ `--. | | | |_ _ __ __ _ _ __ ___ _____ _____ _ __| |__
| /| __| `--. \ | | | _| '__/ _` | '_ ` _ \ / _ \ \ /\ / / _ \| '__| |/ /
| |\ \| |___/\__/ / | | | | | | | (_| | | | | | | __/\ V V / (_) | | | <
\_| \_\____/\____/ \_/ |_| |_| \__,_|_| |_| |_|\___| \_/\_/ \___/|_| |_|\_|

linux中有figlet,可以通过yum安装,下面的是用Python写的

pyfiglet

到https://github.com/pwaller/pyfiglet下载或者clone,

使用whl文件进行安装:

http://www.lfd.uci.edu/~gohlke/pythonlibs/

进入Scripts文件中,使用pip install xx.whl即可。

https://www.douban.com/note/484046487/

使用方法

解压文件,进入文件中,执行python setup.py install ,安装需要的包。

关于setup的理解:http://python.jobbole.com/82077/

安装成功后,在Python中使用 打印的时候直接在renderText中写相应的文字即可

from pyfiglet import Figlet

f = Figlet(font='slant') # 斜体 不slant是默认的字体 是不倾斜的
print(f.renderText('Django')) # 里面写需要的生成的文字,只支持英文

结果:

    ____    _
/ __ \ (_)___ _____ ____ _____
/ / / / / / __ `/ __ \/ __ `/ __ \
/ /_/ / / / /_/ / / / / /_/ / /_/ /
/_____/_/ /\__,_/_/ /_/\__, /\____/
/___/ /____/

深入源码--找自己需要的字体

从font-DEFAULT_FONT-FigletFont类下面的getFonts方法。

打印所有的字体名:

from pyfiglet import Figlet,FigletFont

all_fonts=FigletFont().getFonts()
print(all_fonts)

在pycharm中可以在左侧的源码中定位,直接就找到了所有的文件。

打印的结果:

所有的字体

['1943____', '1row', '3-d', '3d_diagonal', '3x5', '4max', '4x4_offr', '5lineoblique', '5x7', '5x8', '64f1____', '6x10', '6x9', 'acrobatic', 'advenger', 'alligator', 'alligator2', 'alligator3', 'alpha', 'alphabet', 'amc3line', 'amc3liv1', 'amcaaa01', 'amcneko', 'amcrazo2', 'amcrazor', 'amcslash', 'amcslder', 'amcthin', 'amctubes', 'amcun1', 'aquaplan', 'arrows', 'ascii_new_roman', 'ascii___', 'asc_____', 'assalt_m', 'asslt__m', 'atc_gran', 'atc_____', 'avatar', 'a_zooloo', 'B1FF', 'banner', 'banner3-D', 'banner3', 'banner4', 'barbwire', 'basic', 'battlesh', 'battle_s', 'baz__bil', 'bear', 'beer_pub', 'bell', 'benjamin', 'big', 'bigchief', 'bigfig', 'binary', 'block', 'blocks', 'bolger', 'braced', 'bright', 'brite', 'briteb', 'britebi', 'britei', 'broadway', 'broadway_kb', 'bubble', 'bubble_b', 'bubble__', 'bulbhead', 'b_m__200', 'c1______', 'c2______', 'calgphy2', 'caligraphy', 'cards', 'catwalk', 'caus_in_', 'char1___', 'char2___', 'char3___', 'char4___', 'charact1', 'charact2', 'charact3', 'charact4', 'charact5', 'charact6', 'characte', 'charset_', 'chartr', 'chartri', 'chiseled', 'chunky', 'clb6x10', 'clb8x10', 'clb8x8', 'cli8x8', 'clr4x6', 'clr5x10', 'clr5x6', 'clr5x8', 'clr6x10', 'clr6x6', 'clr6x8', 'clr7x10', 'clr7x8', 'clr8x10', 'clr8x8', 'coil_cop', 'coinstak', 'cola', 'colossal', 'computer', 'com_sen_', 'contessa', 'contrast', 'convoy__', 'cosmic', 'cosmike', 'cour', 'courb', 'courbi', 'couri', 'crawford', 'crazy', 'cricket', 'cursive', 'cyberlarge', 'cybermedium', 'cybersmall', 'cygnet', 'c_ascii_', 'c_consen', 'DANC4', 'dancingfont', 'dcs_bfmo', 'decimal', 'deep_str', 'defleppard', 'demo_1__', 'demo_2__', 'demo_m__', 'devilish', 'diamond', 'dietcola', 'digital', 'doh', 'doom', 'dosrebel', 'dotmatrix', 'double', 'doubleshorts', 'drpepper', 'druid___', 'dwhistled', 'd_dragon', 'ebbs_1__', 'ebbs_2__', 'eca_____', 'eftichess', 'eftifont', 'eftipiti', 'eftirobot', 'eftitalic', 'eftiwall', 'eftiwater', 'epic', 'etcrvs__', 'e__fist_', 'f15_____', 'faces_of', 'fairligh', 'fair_mea', 'fantasy_', 'fbr12___', 'fbr1____', 'fbr2____', 'fbr_stri', 'fbr_tilt', 'fender', 'filter', 'finalass', 'fireing_', 'fire_font-k', 'fire_font-s', 'flipped', 'flowerpower', 'flyn_sh', 'fourtops', 'fp1_____', 'fp2_____', 'fraktur', 'funface', 'funfaces', 'funky_dr', 'future_1', 'future_2', 'future_3', 'future_4', 'future_5', 'future_6', 'future_7', 'future_8', 'fuzzy', 'gauntlet', 'georgi16', 'georgia11', 'ghost', 'ghost_bo', 'ghoulish', 'glenyn', 'goofy', 'gothic', 'gothic__', 'graceful', 'gradient', 'graffiti', 'grand_pr', 'greek', 'green_be', 'hades___', 'heart_left', 'heart_right', 'heavy_me', 'helv', 'helvb', 'helvbi', 'helvi', 'henry3d', 'heroboti', 'hex', 'hieroglyphs', 'high_noo', 'hills___', 'hollywood', 'home_pak', 'horizontalleft', 'horizontalright', 'house_of', 'hypa_bal', 'hyper___', 'ICL-1900', 'impossible', 'inc_raw_', 'invita', 'isometric1', 'isometric2', 'isometric3', 'isometric4', 'italic', 'italics_', 'ivrit', 'jacky', 'jazmine', 'jerusalem', 'joust___', 'katakana', 'kban', 'keyboard', 'kgames_i', 'kik_star', 'knob', 'konto', 'kontoslant', 'krak_out', 'larry3d', 'lazy_jon', 'lcd', 'lean', 'letters', 'letterw3', 'letter_w', 'lexible_', 'lildevil', 'lineblocks', 'linux', 'lockergnome', 'madrid', 'mad_nurs', 'magic_ma', 'marquee', 'master_o', 'maxfour', 'mayhem_d', 'mcg_____', 'merlin1', 'merlin2', 'mig_ally', 'mike', 'mini', 'mirror', 'mnemonic', 'modern__', 'modular', 'morse', 'morse2', 'moscow', 'mshebrew210', 'muzzle', 'nancyj-fancy', 'nancyj-improved', 'nancyj-underlined', 'nancyj', 'new_asci', 'nfi1____', 'nipples', 'notie_ca', 'npn_____', 'nscript', 'ntgreek', 'nvscript', 'o8', 'octal', 'odel_lak', 'ogre', 'ok_beer_', 'oldbanner', 'os2', 'outrun__', 'pacos_pe', 'panther_', 'pawn_ins', 'pawp', 'peaks', 'peaksslant', 'pebbles', 'pepper', 'phonix__', 'platoon2', 'platoon_', 'pod_____', 'poison', 'puffy', 'puzzle', 'pyramid', 'p_skateb', 'p_s_h_m_', 'r2-d2___', 'radical_', 'rad_phan', 'rad_____', 'rainbow_', 'rally_s2', 'rally_sp', 'rammstein', 'rampage_', 'rastan__', 'raw_recu', 'rci_____', 'rectangles', 'red_phoenix', 'relief', 'relief2', 'rev', 'reverse', 'ripper!_', 'road_rai', 'rockbox_', 'rok_____', 'roman', 'roman___', 'rot13', 'rotated', 'rounded', 'rowancap', 'rozzo', 'runic', 'runyc', 's-relief', 'sans', 'sansb', 'sansbi', 'sansi', 'santaclara', 'sblood', 'sbook', 'sbookb', 'sbookbi', 'sbooki', 'script', 'script__', 'serifcap', 'shadow', 'shimrod', 'short', 'skateord', 'skateroc', 'skate_ro', 'sketch_s', 'slant', 'slide', 'slscript', 'small', 'smallcaps', 'smisome1', 'smkeyboard', 'smpoison', 'smscript', 'smshadow', 'smslant', 'smtengwar', 'sm______', 'soft', 'space_op', 'spc_demo', 'speed', 'spliff', 'stacey', 'stampate', 'stampatello', 'standard', 'starstrips', 'starwars', 'star_war', 'stealth_', 'stellar', 'stencil1', 'stencil2', 'stforek', 'stop', 'straight', 'street_s', 'sub-zero', 'subteran', 'super_te', 'swampland', 'swan', 'sweet', 'tanja', 'tav1____', 'taxi____', 'tec1____', 'tecrvs__', 'tec_7000', 'tengwar', 'term', 'test1', 'thick', 'thin', 'threepoint', 'ticks', 'ticksslant', 'tiles', 'times', 'timesofl', 'tinker-toy', 'ti_pan__', 'tomahawk', 'tombstone', 'top_duck', 'train', 'trashman', 'trek', 'triad_st', 'ts1_____', 'tsalagi', 'tsm_____', 'tsn_base', 'tty', 'ttyb', 'tubular', 'twin_cob', 'twisted', 'twopoint', 'type_set', 't__of_ap', 'ucf_fan_', 'ugalympi', 'unarmed_', 'univers', 'usaflag', 'usa_pq__', 'usa_____', 'utopia', 'utopiab', 'utopiabi', 'utopiai', 'varsity', 'vortron_', 'war_of_w', 'wavy', 'weird', 'wetletter', 'whimsy', 'wow', 'xbrite', 'xbriteb', 'xbritebi', 'xbritei', 'xchartr', 'xchartri', 'xcour', 'xcourb', 'xcourbi', 'xcouri', 'xhelv', 'xhelvb', 'xhelvbi', 'xhelvi', 'xsans', 'xsansb', 'xsansbi', 'xsansi', 'xsbook', 'xsbookb', 'xsbookbi', 'xsbooki', 'xtimes', 'xtty', 'xttyb', 'yie-ar__', 'yie_ar_k', 'z-pilot_', 'zig_zag_', 'zone7___']

生成文件

遍历列表把生成的字体存入文件中

font_list=FigletFont().getFonts()
with open("fontout","w",encoding='utf8') as f:
for i in font_list:
# f.write(i)
a = Figlet(font=i)
f.write(i)
f.write("\n")
f.write(a.renderText('Django'))
f.write("\n")

文件内容:

地址:http://files.cnblogs.com/files/Python666/figlet_font_out.rar

Linux 系统中的figlet

安装

yum install figlet

使用

figlet xxx

指定字体

查看所有字体

showfigfonts

使用指定的字体

figlet -f smslant xxxx

参考:

https://stackoverflow.com/questions/9632995/how-to-easily-print-ascii-art-text

https://github.com/pwaller/pyfiglet

http://ju.outofmemory.cn/entry/157818

http://helloit.blog.51cto.com/440343/810343

使用Python生成ASCII字符画的更多相关文章

  1. AsciiMorph - 新奇的 ASCII 字符画生成工具&插件

    AsciiMorph 是一个新奇的 ASCII 字符画生成工具和开源插件.字符画(ASCII Art)的历史可以追溯到几十年前,起初是用在图形显示功能受限的设备上,用ASCII字符集里的可打印字符来拼 ...

  2. 将图片转为ASCII字符画

    原文:将图片转为ASCII字符画 Copyright 2012 Conmajia 源代码下载:点击这里 什么是字符画?就是用ASCII字符来近似组成图像,就像这样: ╭╮ ╭╮ ││ ││ ╭┴┴—— ...

  3. Python 图片转字符画

    Python 图片转字符画 一.课程介绍 1. 课程来源 原创 2. 内容简介 本课程讲述怎样使用 Python 将图片转为字符画 3. 前置课程 Python编程语言 Linux 基础入门(新版) ...

  4. 使用Java代码将一张图片生成为字符画

    测试的图片: 输出的结果: 代码: package test; import java.awt.image.BufferedImage; import java.io.File; import jav ...

  5. Python 图片转字符画 学习笔记

    Python 图片转字符画 学习笔记 标签(空格分隔): Python 声明:此文章和所有代码是学习笔记,非原创,原文教程地址:https://www.shiyanlou.com/courses/37 ...

  6. python图片转字符画(转)

    先上代码: from PIL import Image import argparse #命令行输入参数处理 parser = argparse.ArgumentParser() parser.add ...

  7. Python 视频转字符画 - 进阶

    这篇文章是 视频转字符动画-Python-60行代码 的后续,如果感兴趣,请先看看它. 1. 速度优化 要是每次播放都要等个一分钟,也太痛苦了一点. 所以可以用 pickle 模块把 video_ch ...

  8. [笔记] Python 图片转字符画

    一.介绍 用Python 代码完成图片转字符画 二.python 环境 Python 3.6.6 pillow 5.1.0  Python 图像处理库, 需要另外安装 三.原理 gray = 0.21 ...

  9. Python图片转字符画

    PIL安装很麻烦,推荐下载exe直接安装 PIL官网:http://pythonware.com/products/pil/ 但现在里面下载链接访问不了,我把32位和64位版本上传到博客园以供下载 P ...

随机推荐

  1. Visual Studio容器项目工程化心得

    引言 关注博主的网友会看到我使用ASP.NET Core 容器化部署企业级项目的过程, 回想到开发过程中,鄙人有一些工程化心得, 分享给同学们. 项目工程化 因为本项目涉及单元测试Project.容器 ...

  2. 笔记-JavaWeb学习之旅18

    AJAX:ASynchronous JavaScript And XML 异步的JavaScript 和XML 异步和同步:客户端和服务器端相互通信的基础上 同步:客户端操作后必须等待服务器端的响应, ...

  3. Composer的简单使用

    .前期准备: 1.下载安装包,https://getcomposer.org/download/ 2.在php.ini文档中打开extension=php_openssl.dll 3.下载php_ss ...

  4. Domination

    题目链接 #include <bits/stdc++.h> using namespace std; typedef long long ll; inline ll read(){ , f ...

  5. ubuntu 16.04 单用户____修改忘记密码

    1.开机按ESC,出现如下界面,选中如下选项 2.按回车键进入如下界面,然后选中有recovery mode的选项 3.按e进入如下界面,找到图中红色框的recovery nomodeset并将其删掉 ...

  6. BZOJ-3555:企鹅QQ(字符串哈希)

    PenguinQQ是中国最大.最具影响力的SNS(Social Networking Services)网站,以实名制为基础,为用户提供日志.群.即时通讯.相册.集市等丰富强大的互联网功能体验,满足用 ...

  7. 安装Jaspersoft Studio

    下载位置:http://community.jaspersoft.com/project/jaspersoft-studio/releases.

  8. Ubuntu14.04创建WiFi热点

    右键右上角网络图标→Edit Connections →Wi-Fi→Add→Wi-Fi→Create→SSID(wifi名称)→Mode(Ad-hoc)→IPv4 Settings→Methods(S ...

  9. readonly与const的区别

    readonly 关键字与 const 关键字不同.const 字段只能在该字段的声明中初始化.readonly字段可以在声明或构造函数中初始化.因此,根据所使用的构造函数,readonly字段可能具 ...

  10. 架构演进历程及为什么选择Spring Cloud

    单体式架构: 垂直拆分: 垂直拆分的特点: 分布式服务: 分布式服务的特点: SOA面向服务的架构: 服务治理: 微服务: 微服务结构: 服务调用方式: http客户端工具: