简易字母表白

`import matplotlib.pyplot as pltimport seabornimport numpy# 定义方法def draw_love(): #拼凑字母    l = numpy.arange(0, 4, 0.01)    L = 1.0 / l    theta = numpy.arange(-4, 4, 0.01)    o = 3.0 * numpy.cos(theta)    O = 3.0 * numpy.sin(theta)    v = numpy.arange(-4, 4, 0.01)    V = numpy.abs(-2.0 * v)    e = numpy.arange(-3, 3, 0.01)    E = -1.0 * numpy.abs(numpy.sin(e))    y = numpy.arange(-10, 10, 0.01)    Y = numpy.log2(numpy.abs(y))    u = numpy.arange(-4, 4, 0.01)    U = 2.0 * u ** 2    points = []    for heartY in numpy.linspace(-100, 100, 500):        for heartX in numpy.linspace(-100, 100, 500):            if ((heartX * 0.03) ** 2 + (heartY * 0.03) ** 2 - 1) ** 3 - (heartX * 0.03) ** 2 * (                    heartY * 0.03) ** 3 <= 0:points.append({"x": heartX, "y": heartY})# 设置直角坐标系heart_x = list(map(lambda point: point["x"], points))heart_y = list(map(lambda point: point["y"], points))# 添加网格fig = plt.figure(figsize=(13, 7))ax_L = fig.add_subplot(2, 4, 1)ax_O = fig.add_subplot(2, 4, 2)ax_V = fig.add_subplot(2, 4, 3)ax_E = fig.add_subplot(2, 4, 4)ax_Y = fig.add_subplot(2, 4, 5)ax_O_2 = fig.add_subplot(2, 4, 6)ax_U = fig.add_subplot(2, 4, 7)ax_heart = fig.add_subplot(2, 4, 8)# 设置坐标ax_L.plot(l, L)ax_O.plot(o, O)ax_V.plot(v, V)ax_E.plot(E, e)ax_Y.plot(y, Y)ax_Y.axis([-10.0, 10.0, -10.0, 5.0])ax_O_2.plot(o, O)ax_U.plot(u, U)ax_heart.scatter(heart_x, heart_y, s=10, alpha=0.5)# 设置颜色plt.plot(color='red')# 展示结果plt.show()# 主函数if __name__ == '__main__':seaborn.set_style('dark')draw_love()`

动图小爱心

`import turtleimport timedef hart_arc():    for i in range(200):        turtle.right(1)        turtle.forward(2)def move_pen_position(x, y):    turtle.hideturtle()  # 隐藏画笔（先）    turtle.up()  # 提笔    turtle.goto(x, y)  # 移动画笔到指定起始坐标（窗口中心为0,0）    turtle.down()  # 下笔    turtle.showturtle()  # 显示画笔love = input("请输入表白话语：")signature = input("请签署你的名字:")date=input("请写上日期：")if love == '':    love = 'I Love You'turtle.setup(width=800, height=500)  # 窗口（画布）大小turtle.color('red', 'pink')  # 画笔颜色turtle.pensize(3)  # 画笔粗细turtle.speed(1)  # 描绘速度# 初始化画笔起始坐标move_pen_position(x=0, y=-180)  # 移动画笔位置turtle.left(140)  # 向左旋转140度turtle.begin_fill()  # 标记背景填充位置# 画图和展示turtle.forward(224)  # 向前移动画笔，长度为224# 画爱心圆弧hart_arc()  # 左侧圆弧turtle.left(120)  # 调整画笔角度hart_arc()  # 右侧圆弧# 画心形直线（ 右下方 ）turtle.forward(224)turtle.end_fill()  # 标记背景填充结束位置move_pen_position(x=70, y=160)  # 移动画笔位置turtle.left(185)  # 向左旋转180度turtle.circle(-110,185)  # 右侧圆弧# 画心形直线（ 右下方 ）#turtle.left(20)  # 向左旋转180度turtle.forward(50)move_pen_position(x=-180, y=-180)  # 移动画笔位置turtle.left(180)  # 向左旋转140度# 画心形直线（ 左下方 ）turtle.forward(600)  # 向前移动画笔，长度为224# 在心形中写上表白话语move_pen_position(0,50)  # 表白语位置turtle.hideturtle()  # 隐藏画笔turtle.color('#CD5C5C', 'pink')  # 字体颜色# font:设定字体、尺寸（电脑下存在的字体都可设置）  align:中心对齐turtle.write(love, font=('Arial', 20, 'bold'), align="center")# 签写署名和日期if (signature != '') & (date != ''):    turtle.color('red', 'pink')    time.sleep(2)    move_pen_position(220, -180)    turtle.hideturtle()  # 隐藏画笔    turtle.write(signature, font=('Arial', 20), align="center")    move_pen_position(220, -220)    turtle.hideturtle()  # 隐藏画笔    turtle.write(date, font=('Arial', 20), align="center")#点击窗口关闭程序window = turtle.Screen()window.exitonclick()`

总结

PS：公号内回复「Python」即可进入Python 新手学习交流群，一起 100 天计划！

【​代码获取方式​】