Python的turtle模块画爱心箭(附源码)

发布于:2022-11-03 ⋅ 阅读:(598) ⋅ 点赞:(0)

Python的turtle模块画爱心箭源码

import turtle as t
t.hideturtle()
t.speed(100)
def f(a,b):#画箭,a,b为箭尖坐标
    t.penup()
    t.goto(a,b)
    t.pendown()
    t.pencolor("pink")#画半颗爱心
    t.fillcolor("pink")
    t.begin_fill()
    t.fd(40)
    t.circle(20,180)
    t.right(135)
    t.penup()
    t.fd(85)
    t.pensize(9)
    t.pencolor('NavajoWhite3')
    for i in range(3):#画箭羽
        t.penup()
        t.fd(15)
        t.pendown()
        t.left(45)
        for z in range(2):
            t.fd(30)
            t.bk(30)
            t.right(90)
        t.left(135)
    t.pensize(6)#画箭体
    t.pencolor('brown4')
    t.bk(130)
    t.left(45)
    t.pencolor("pink")#画另外半颗爱心
    t.fillcolor("pink")
    t.pensize(1)
    t.circle(20,180)
    t.fd(40)
    t.end_fill()
    def z(x,y,z):#画内层爱心,x为距离,y为大小,z为颜色#x+y应为40
        t.penup()
        t.bk(x)
        t.left(90)
        t.fd(x)
        t.fillcolor(z)
        t.begin_fill()
        t.fd(y)
        t.circle(y/2,180)
        t.right(90)
        t.circle(y/2,180)
        t.fd(y)
        t.end_fill()
        t.penup()
        t.fd(x)
        t.left(90)
        t.bk(x)
        t.right(90)
    z(10,30,'red')
    z(20,20,'red3')
    z(30,10,'red4')
    t.left(90)
f(0,0)
f(10,110)
f(150,50)
def i(a,b,c,d,e):#打印文字,a,b为坐标,c为颜色,d为内容,e为大小
    t.penup()
    t.goto(a,b)
    t.color(c)
    write=t.write(d,font=('宋体',e,'normal'))
i(-210,-100,'green','接招,XXX',60)
i(180,-150,'red','''你的父亲
 XXX''',20)
import datetime
time=datetime.datetime.today()
i(180,-180,'red','-'+str(time),15)
t.done()

效果展示:
效果展示


网站公告

今日签到

点亮在社区的每一天
去签到