首页 > 技术文章 > Python 520表白

mliu 2022-05-20 16:17 原文

PS:又是开心营业的一天,距离上次开心营业,已过去95天

效果图:

 

 

 

上代码:

# -*- coding: UTF-8 -*-
import os
import turtle as t

t.title('关注博客不迷路:www.cnblogs.com/mliu(又是开心营业的一天)')
t.speed(20)
# t.screensize(1000, 800)
t.setup(startx=1050, starty=0, width=800, height=600)
t.hideturtle()
print('画爱心')


# 画爱心
def heart(x, y):
    t.penup()
    t.goto(x, y)
    t.pendown()
    t.color('pink')
    t.setheading(50)
    t.circle(-5, 180)
    t.circle(-45, 12)
    t.setheading(130)
    t.circle(-45, 12)
    t.circle(-5, 180)


heart(-30, 155)
heart(-220, 145)
heart(-210, 60)
heart(-100, 100)
heart(-20, 20)
heart(-70, 130)
heart(-140, -20)
heart(30, 100)
heart(-60, -20)
heart(10, 60)
heart(-100, -70)
heart(20, 145)
heart(-140, -20)
heart(-130, 130)
heart(-180, 20)
heart(-170, 155)
heart(-230, 100)


def write_mes(x, y, size, ss):
    t.hideturtle()
    t.penup()
    t.goto(x, y)
    t.pendown()
    t.pencolor('black')
    t.write(ss, font=('Times New Roman', size, 'normal'))


# 画红心
print('画红心')


def heart_fill(x, y):
    t.penup()
    t.goto(x, y)
    t.pendown()
    t.color('red', 'red')
    t.begin_fill()
    t.setheading(50)
    t.circle(-5, 180)
    t.circle(-45, 12)
    t.setheading(130)
    t.circle(-45, 12)
    t.circle(-5, 180)
    t.end_fill()


x = 90
y = 110
# 爱心左
write_mes(x, y, 11, '阿珍爱上了阿强')
heart_fill(-100, 100)
heart_fill(-70, 130)
heart_fill(-30, 155)
heart_fill(20, 145)
heart_fill(30, 100)
write_mes(x, y - 30, 11, '在一个有星星的夜晚')
heart_fill(10, 60)
heart_fill(-20, 20)
heart_fill(-60, -20)
heart_fill(-100, -70)
# 爱心右
write_mes(x, y - 30 * 2, 11, '')
heart_fill(-140, -20)
heart_fill(-180, 20)
heart_fill(-210, 60)
heart_fill(-230, 100)
write_mes(x, y - 30 * 3, 11, '虽然说人生并没有什么意义')
heart_fill(-220, 145)
heart_fill(-170, 155)
heart_fill(-130, 130)
write_mes(x, y - 30 * 4, 11, '但是爱情确实让生活更加美丽')
t.speed(15)
print('画心动线')


def heart_bit():
    # 心动线
    t.penup()
    t.goto(-170, 40)
    t.pendown()
    t.pencolor('red')
    t.setheading(0)
    t.pensize(2)
    t.forward(10)
    # 小波浪
    t.setheading(45)
    t.circle(50, 10)
    t.setheading(0)
    t.circle(-3, 90)
    t.circle(50, 5)
    # 横线
    t.setheading(0)
    t.forward(10)
    # 下尖峰
    t.setheading(-80)
    t.forward(7)
    t.setheading(70)
    t.forward(25)
    t.setheading(-85)
    t.forward(29)
    t.setheading(70)
    t.forward(13)
    t.setheading(0)
    t.forward(15)

    # 画心
    t.setheading(150)
    t.circle(-20, 40)
    t.circle(-10, 170)
    t.setheading(70)
    t.circle(-10, 170)
    t.circle(-20, 40)
    t.setheading(0)
    t.forward(15)
    # 2X
    t.setheading(-80)
    t.forward(7)
    t.setheading(70)
    t.forward(25)
    t.setheading(-85)
    t.forward(29)
    t.setheading(70)
    t.forward(13)
    t.setheading(0)
    t.forward(15)
    t.setheading(0)
    t.forward(10)
    t.setheading(45)
    t.circle(50, 10)
    t.setheading(0)
    t.circle(-3, 90)
    t.circle(50, 5)
    t.setheading(0)
    t.forward(10)


def write_name(x, y, size, ss):
    t.hideturtle()
    t.penup()
    t.goto(x, y)
    t.pendown()
    t.pencolor('black')
    t.write(ss, font=('Times New Roman', size, 'normal'))


def undo_back():
    t.undo()
    t.undo()
    t.undo()
    t.undo()
    t.undo()
    t.undo()
    t.undo()
    t.undo()
    t.undo()
    t.undo()


def undo_back2():
    t.undo()
    t.undo()


def name_heart_bit():
    # 写两个人的姓名
    write_name(-180, 70, 11, '阿强')
    write_name(-180, 70, 11, '阿强')
    write_name(-180, 70, 11, '阿强')
    heart_bit()
    write_name(-60, 70, 11, '阿珍')
    write_name(-60, 70, 11, '阿珍')
    write_name(-60, 70, 11, '阿珍')
    write_name(-60, 70, 11, '阿珍')
    write_name(-60, 70, 11, '阿珍')
    undo_back()
    undo_back()
    undo_back()
    undo_back()
    undo_back()
    undo_back()
    undo_back()
    undo_back()
    undo_back()
    undo_back2()


while 1:
    name_heart_bit()

 

推荐阅读