python完美表白代码
1.源代码
import turtle import time # 清屏函数 def clear_all(): turtle.penup() turtle.goto(0, 0) turtle.color('white') turtle.pensize(800) turtle.pendown() turtle.setheading(0) turtle.fd(300) turtle.bk(600) # 重定位海龟的位置 def go_to(x, y, state): turtle.pendown() if state else turtle.penup() turtle.goto(x, y) # 画爱心 def draw_heart(size): turtle.color('red', 'pink') turtle.pensize(2) turtle.pendown() turtle.setheading(150) turtle.begin_fill() turtle.fd(size) turtle.circle(size * -3.745, 45) turtle.circle(size * -1.431, 165) turtle.left(120) turtle.circle(size * -1.431, 165) turtle.circle(size * -3.745, 45) turtle.fd(size) turtle.end_fill() # 画出发射爱心的小人 def draw_people(x, y): turtle.penup() turtle.goto(x, y) turtle.pendown() turtle.pensize(2) turtle.color('black') turtle.setheading(0) turtle.circle(60, 360) turtle.penup() turtle.setheading(90) turtle.fd(75) turtle.setheading(180) turtle.fd(20) turtle.pensize(4) turtle.pendown() turtle.circle(2, 360) turtle.setheading(0) turtle.penup() turtle.fd(40) turtle.pensize(4) turtle.pendown() turtle.circle(-2, 360) turtle.penup() turtle.goto(x, y) turtle.setheading(-90) turtle.pendown() turtle.fd(20) turtle.setheading(0) turtle.fd(35) turtle.setheading(60) turtle.fd(10) turtle.penup() turtle.goto(x, y) turtle.setheading(-90) turtle.pendown() turtle.fd(40) turtle.setheading(0) turtle.fd(35) turtle.setheading(-60) turtle.fd(10) turtle.penup() turtle.goto(x, y) turtle.setheading(-90) turtle.pendown() turtle.fd(60) turtle.setheading(-135) turtle.fd(60) turtle.bk(60) turtle.setheading(-45) turtle.fd(30) turtle.setheading(-135) turtle.fd(35) turtle.penup() # 第一个画面,显示文字 def page0(): turtle.penup() turtle.goto(-350, 0) turtle.color('red') turtle.write('有你生活成缤纷多彩', font=('宋体', 60, 'normal')) turtle.penup() turtle.goto(-160, -180) draw_heart(30) turtle.penup() turtle.goto(0, -180) draw_heart(30) turtle.penup() turtle.goto(160, -180) draw_heart(30) time.sleep(3) # 第二个画面,显示发射爱心的小人 def page1(): turtle.speed(10) turtle.penup() turtle.goto(-200, -200) turtle.color('red') turtle.pendown() turtle.write('mj mq', font=('wisdom', 50, 'normal')) turtle.penup() turtle.goto(0, -180) draw_heart(10) draw_people(-250, 20) turtle.penup() turtle.goto(-150, -30) draw_heart(14) turtle.penup() turtle.goto(-20, -60) draw_heart(25) turtle.penup() turtle.goto(250, -100) draw_heart(45) turtle.hideturtle() # 写送给谁 turtle.pencolor("PINK") turtle.penup() turtle.goto(300, 200) turtle.write(str, move=False, align='center', font=("方正舒体", 30, 'normal')) time.sleep(3) def main(): turtle.setup(900, 500) page0() clear_all() page1() clear_all() turtle.done() if __name__ == '__main__': str = input('请输入表白语:') main()