用 *号输出字母 C的图案
方法1:
print(" ***** ")print(" ** * ")print(" ** ")print(" ** ")print(" ** * ")print(" ***** ")
方法2:
ch = [[0, 1, 1, 0], [1, 0, 0, 1], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 1], [0, 1, 1, 0]]for i in range(len(ch)): for j in ch[i]: if j == 0: print(" ",end="") else: print("*", end=" ") print()
输出结果:
方法3:
from PIL import Image,ImageDraw,ImageFontimport numpy as nptext = "C"myfont = ImageFont.truetype("msyh.ttc", 12) # 在代码所在目录下需要放置字体文件,此处为msyh.tccsize = myfont.getsize(text)img = Image.new("1", size, "black")draw = ImageDraw.Draw(img)draw.text((0,0), text, "white", font=myfont)pixels = np.array(img, dtype=np.uint8)chars = np.array([' ', '*'], dtype="U1")[pixels]strings = chars.view('U' + str(chars.shape[1])).flatten()print("\n".join(strings))
输出结果: