El módulo pyfiglet en Python permite la creación de arte ASCII a partir de texto plano. Para insatlarlo, utiliza pip install pyfiglet.
Este módulo proporciona una gran variedad de fuentes para estilizar la salida de texto. A continuación, se muestra un ejemplo de cómo iterar a través de una lista de fuentes disopnibles, generar texto ASCII con cada una y guardarlo en un archivo.
from pyfiglet import Figlet
import os
# Lista de fuentes disponibles en pyfiglet
fuentes_ascii = [
"standard", "slant", "small", "script", "serifcap", "shadow", "short",
"skate_ro", "skateord", "skateroc", "sketch_s", "slant", "slide", "slscript",
"sm______", "small", "smisome1", "smkeyboard", "smscript", "smshadow",
"smslant", "smtengwar", "space_op", "spc_demo", "speed", "stacey",
"stampatello", "standard", "star_war", "starwars", "stealth_", "stellar",
"stencil1", "stencil2", "stop", "straight", "street_s", "subteran",
"super_te", "t__of_ap", "tanja", "tav1____", "taxi____", "tec_7000",
"tec1____", "tecrvs__", "tengwar", "term", "thick", "thin", "threepoint",
"ti_pan__", "ticks", "ticksslant", "tiles", "times", "timesofl",
"tinker-toy", "tomahawk", "tombstone", "top_duck", "trashman", "trek",
"triad_st", "ts1_____", "tsalagi", "tsm_____", "tsn_base", "tty", "ttyb",
"tubular", "twin_cob", "twopoint", "type_set", "ucf_fan_", "ugalympi",
"unarmed_", "univers", "upper.flc", "usa_____", "usa_pq__", "usaflag",
"utopia", "utopiab", "utopiabi", "utopiai", "vortron_", "war_of_w", "wavy",
"weird", "whimsy", "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_k",
"yie-ar__", "zig_zag_", "zone7___", "z-pilot_", "3-d", "3x5", "4x4_offr",
"5lineoblique", "5x7", "5x8", "6x9", "6x10", "64f1____", "1943____",
"a_zooloo", "acrobatic", "advenger", "alligator", "alligator2", "alphabet",
"aquaplan", "arrows", "asc_____", "ascii___", "assalt_m", "asslt__m",
"atc_____", "atc_gran", "avatar", "b_m__200", "banner", "banner3",
"banner3-D", "banner4", "barbwire", "basic", "battle_s", "battlesh",
"baz__bil", "beer_pub", "bell", "big", "bigchief", "binary", "block",
"brite", "briteb", "britebi", "britei", "broadway", "bubble", "bubble__",
"bubble_b", "bulbhead", "c_ascii_", "c_consen", "c1______", "c2______",
"calgphy2", "caligraphy", "catwalk", "caus_in_", "char1___", "char2___",
"char3___", "char4___", "charact1", "charact2", "charact3", "charact4",
"charact5", "charact6", "characte", "charset_", "chartr", "chartri",
"chunky", "clb6x10", "clb8x8", "clb8x10", "cli8x8", "clr4x6", "clr5x6",
"clr5x8", "clr5x10", "clr6x6", "clr6x8", "clr6x10", "clr7x8", "clr7x10",
"clr8x8", "clr8x10", "coil_cop", "coinstak", "colossal", "com_sen_",
"computer", "contessa", "contrast", "convoy__", "cosmic", "cosmike",
"cour", "courb", "courbi", "couri", "crawford", "cricket", "cursive",
"cyberlarge", "cybermedium", "cybersmall", "d_dragon", "dcs_bfmo",
"decimal", "deep_str", "defleppard", "demo_1__", "demo_2__", "demo_m__",
"devilish", "diamond", "digital", "doh", "doom", "dotmatrix", "double",
"drpepper", "druid___", "dwhistled", "e__fist_", "ebbs_1__", "ebbs_2__",
"eca_____", "eftichess", "eftifont", "eftipiti", "eftirobot", "eftiwall",
"eftiwater", "epic", "etcrvs__", "f15_____", "faces_of", "fair_mea",
"fairligh", "fantasy_", "fbr_stri", "fbr_tilt", "fbr1____", "fbr2____",
"fbr12___", "fender", "finalass", "fireing_", "flyn_sh", "fourtops",
"fp1_____", "fp2_____", "fraktur", "funky_dr", "future_1", "future_2",
"future_3", "future_4", "future_5", "future_6", "future_7", "future_8",
"fuzzy", "gauntlet", "ghost_bo", "goofy", "gothic", "gothic__", "graceful",
"gradient", "graffiti", "grand_pr", "greek", "green_be", "hades___",
"heavy_me", "helv", "helvb", "helvbi", "helvi", "heroboti", "hex",
"high_noo", "hills___", "hollywood", "home_pak", "house_of", "hypa_bal",
"hyper___", "inc_raw_", "invita", "isometric1", "isometric2", "isometric3",
"isometric4", "italic", "italics_", "ivrit", "jazmine", "jerusalem",
"joust___", "katakana", "kban", "kgames_i", "kik_star", "krak_out",
"larry3d", "lazy_jon", "lcd", "lean", "letter_w", "letters", "letterw3",
"lexible_", "linux", "lockergnome", "lower.flc", "mad_nurs", "madrid",
"magic_ma", "marquee", "master_o", "maxfour", "mayhem_d", "mcg_____",
"mig_ally", "mike", "mini", "mirror", "mnemonic", "modern__", "morse",
"moscow", "mshebrew210", "nancyj", "nancyj-fancy", "nancyj-underlined",
"new_asci", "nfi1____", "nipples", "notie_ca", "npn_____", "ntgreek",
"null.flc", "nvscript", "o8", "octal", "odel_lak", "ogre", "ok_beer_",
"os2", "outrun__", "p_s_h_m_", "p_skateb", "pacos_pe", "panther_",
"pawn_ins", "pawp", "peaks", "pebbles", "pepper", "phonix__", "platoon_",
"platoon2", "pod_____", "poison", "puffy", "pyramid", "r2-d2___",
"rad_____", "rad_phan", "radical_", "rainbow_", "rally_s2", "rally_sp",
"rampage_", "rastan__", "raw_recu", "rci_____", "rectangles", "relief",
"relief2", "rev", "ripper!_", "road_rai", "rockbox_", "rok_____",
"roman", "roman___", "rot13.flc", "rot13", "rounded", "rowancap",
"rozzo", "runic", "runyc", "sans", "sansb", "sansbi", "sansi", "sblood",
"sbook", "sbookb", "sbookbi", "sbooki", "script", "script__", "serifcap",
"shadow", "shimrod", "short", "skate_ro", "skateord", "skateroc", "sketch_s",
"slant", "slide", "slscript", "sm______", "small", "smisome1", "smkeyboard",
"smscript", "smshadow", "smslant", "smtengwar", "space_op", "spc_demo",
"speed", "stacey", "stampatello", "standard", "star_war", "starwars",
"stealth_", "stellar", "stencil1", "stencil2", "stop", "straight",
"street_s", "subteran", "super_te", "t__of_ap", "tanja", "tav1____",
"taxi____", "tec_7000", "tec1____", "tecrvs__", "tengwar", "term",
"thick", "thin", "threepoint", "ti_pan__", "ticks", "ticksslant",
"tiles", "times", "timesofl", "tinker-toy", "tomahawk", "tombstone",
"top_duck", "trashman", "trek", "triad_st", "ts1_____", "tsalagi",
"tsm_____", "tsn_base", "tty", "ttyb", "tubular", "twin_cob", "twopoint",
"type_set", "ucf_fan_", "ugalympi", "unarmed_", "univers", "upper.flc",
"usa_____", "usa_pq__", "usaflag", "utopia", "utopiab", "utopiabi",
"utopiai", "vortron_", "war_of_w", "wavy", "weird", "whimsy", "xbrite",
"xbriteb", "xbritebi", "xbritei", "xchartr", "xchartri", "xcour",
"xcourb", "xcourbi", "xcouri", "xhelv", "xhelvb", "xhelvbi", "xhelvi",
"xsans", "xsansb", "xsansbi", "xsansi", "xsbook", "xsbookb", "xsbookbi",
"xsbooki", "xtimes"
]
# Nombre del archivo donde se guardarán los resultados
nombre_archivo = 'fuentes_ascii.txt'
# Crear o sobrescribir el archivo con modo escritura ('w') y codificación UTF-8
with open(nombre_archivo, 'w', encoding='utf-8') as archivo_salida:
# Iterar sobre cada nombre de fuente en la lista
for nombre_fuente in fuentes_ascii:
try:
# Inicializar el objeto Figlet con la fuente actual
generador_fig = Figlet(font=nombre_fuente)
# Renderizar el texto de ejemplo "Python"
texto_renderizado = generador_fig.renderText('Python')
# Imprimir el texto renderizado en la consola
print(f"--- Fuente: {nombre_fuente} ---")
print(texto_renderizado)
# Escribir el nombre de la fuente y el texto renderizado en el archivo
archivo_salida.write(f"--- Fuente: {nombre_fuente} ---\n")
archivo_salida.write(texto_renderizado)
archivo_salida.write("\n\n") # Añadir líneas en blanco para separar las entradas
except Exception as e:
# Manejar posibles errores si una fuente no es válida o causa problemas
print(f"Error al procesar la fuente {nombre_fuente}: {e}")
archivo_salida.write(f"Error al procesar la fuente {nombre_fuente}: {e}\n\n")
print(f"Se ha generado el archivo '{nombre_archivo}' con todas las fuentes y sus resultados.")
Este script te permite generar una amplia gama de estilos de texto para tus aplicaciones. A continuación, se muestran algunos ejemplos de cómo se ve el texto con diferentes fuentes:
--- Fuente: xtty ---
#
# #
# # # # #### # # ## # #
## # # # # ## # # # ## #
# # # # # # # # # # #
# # ## # # # # # # #
# # ## # # # # # # #
### # ## # # ## # #
# #
# #
--- Fuente: xttyb ---
##
## ##
# ## ## # ##### ## # ### # ##
## ## ## # ## ##### ## ## ## ##
## ## ## ## ## ## ## ## ## ## ##
## ## # # ## ## ## ## ## ## ##
## ## ### ## ## ## ## ## ## ##
#### ## ### ## ## ### ## ##
## #
## ##
--- Fuente: yie_ar_k ---
# # # #
##### #
###### #
# # ## #
# # # #
# # # #
## # #
# # # #
--- Fuente: yie-ar__ ---
# # # #
##### #
###### #
# # ## #
# # # #
# # # #
## # #
# # # #
--- Fuente: zig_zag_ ---
######## ### # # # # ### # # ##### #
# # # # ## # ## ## # ### # # # # #######
# ### # # # ## # ### # #### # # # # # #####
##### # ## # ## # ## #### ##### # # # # #
### ## # ## ## # ### # ##### # # # #
## ## ## ## ## #
### ### ###
## # ## ###
--- Fuente: zone7___ ---
## ## ##
## # ## ##
## # ## ##
#### # ## ##
#### # ### ## ##
## #### ## ##
## ## ## ##
## ## ## ##
--- Fuente: z-pilot_ ---
######## ## ######## ## ##### ## # ## # # ##
######## ## ######## ######## ## # ## ## # ##
######## # ######## # # # # # # ## # # #
######## # ######## ## # # # # ## # # #
######## ## ######## ## # ## #
######## ## ######## ## # #### #
######## # # ###### ## # ######## ## # ##
######## # # ###### ## # ######## ## # ##
--- Fuente: 3-d ---
** **
****** ** ** /** /**
/**///** //** ** ******/** ****** *******
/** /** //*** ///**/ /****** **////**//**///**
/****** /** /** /**///**/** /** /** /**
/**/// ** /** /** /**/** /** /** /**
/** ** //** /** /**//****** *** /**
// // // // // ////// /// //
--- Fuente: 3x5 ---
# #
### # # ### ### ### ##
# # ### # # # # # # #
### # ## # # ### # #
# ###
--- Fuente: 4x4_offr ---
######## ## ## ## ######## ##
######## ## ## ## ######## ###
## ## ## ## ## ###
## ## ## ## ## ###
## ## ## ## ## ###
## ## ## ## ## ###
## ## ## ## ## ###
## ## ## ## ## ##
--- Fuente: 5lineoblique ---
___ __ ___ / __ ___ __
// ) ) // / / / / // ) ) // ) ) // ) )
//___/ / ((___/ / / / // / / // / / // / /
// / / / / // / / ((___/ / // / /
--- Fuente: 5x7 ---
# #
# #
### # # ### ### ## ###
# # # # # # # # # # #
# # # # # # # # # # #
### # ## # # ## # #
# #
--- Fuente: 5x8 ---
# #
# # # # ##
# ## # ####
## ## # ### #
# # # # # # ##
### # # # #
# ## #
## # #
--- Fuente: 6x9 ---
# #
# #
### #
### # # # # # ## ###
# # # # # # ## # # # # #
# # ## # # # # # # # # #
### ## # # # ## # #
# # #
# ##
--- Fuente: 6x10 ---
# #
# #
# ## # # #### # ## ### # ##
## # # # # ## # # # ## #
## # # ## # # # # # # #
# ## ## # # # # # # # # #
# # ## # # ### # #
# # #
# ###
--- Fuente: 64f1____ ---
# # ## ### ### ## # # ## # # # #
# # # # # ## ### ###### ### #
# # ## ### # # # # ### ### # #### #####
### ## # # #### #### # ## # #
# #### ### ### ## # ### ### ##
# ## # ### # ## # ## ## # # ## #
## # # # # ## ### ### ### ## # #
# # # ### ### # # ## # ## ## #
--- Fuente: 1943____ ---
### # # ### # # ### # # ### # # ### # #
### # # ### # # ### # # ### # # ### # #
### # # ### # # ### # # ### # # ### # #
### # # ### # # ### # # ##### ### # # ### # #
### # # ### # # ### # # ## ## ### # # ### # #
### # # ### # # ### # # ## ## ### # # ### # #
### # # ### # # ### # # ##### ### # # ### # #
### # # ### # # ### # # ## ## ### # # ### # #
--- Fuente: a_zooloo ---
## ## ### ##### ##### ## ## #####
## ## ### ##### ##### ## ## #####
### ### ### ### ####### ##### ### ### #######
### ### ### ### ####### ##### ### ### #######
### ### ####### ### ## ### ####### ###
### ### ####### ### ## ### ####### ###
####### ##### ## ## ## ###### ## ###
####### ##### ## ## ## ###### ## ###
--- Fuente: acrobatic ---
o o
<|> <|>
< > / >
\o_ __o o o | \o__ __o o__ __o \o__ __o
| v\ <|> <|> o__/_ | v\ /v v\ | |>
/ \ <\ < > < > | / \ <\ /> <\ / \ / \
\o/ / \o o/ | \o/ o/ \ / \o/ \o/
| o v\ /v o | <| o o | |
/ \ __/> <\/> <\__ / \ / \ <\__ __/> / \ / \
\o/ /
| o
/ \ __/>
Puedes ejecutar el código anterior para generar un archivo de texto con todas las fuentes disponibles y sus representaciones ASCII.