利用Python如何画一颗心、小人发射爱心
源码:
#!/usr/bin/envpython
#-*-coding:utf-8-*-
importturtle
importtime
#画心形圆弧
defhart_arc():
foriinrange(200):
turtle.right(1)
turtle.forward(2)
defmove_pen_position(x,y):
turtle.hideturtle()#隐藏画笔(先)
turtle.up()#提笔
turtle.goto(x,y)#移动画笔到指定起始坐标(窗口中心为0,0)
turtle.down()#下笔
turtle.showturtle()#显示画笔
#初始化
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()#标记背景填充结束位置
#点击窗口关闭程序
window=turtle.Screen()
window.exitonclick()
效果图:
源码:
importturtleast
fromtimeimportsleep
defgo_to(x,y):
t.up()
t.goto(x,y)
t.down()
defhead(x,y,r):
go_to(x,y)
t.speed(20)
t.circle(r)
leg(x,y)
defleg(x,y):
t.right(90)
t.forward(180)
t.right(30)
t.forward(100)
t.left(120)
go_to(x,y-180)
t.forward(100)
t.right(120)
t.forward(100)
t.left(120)
hand(x,y)
defhand(x,y):
go_to(x,y-60)
t.forward(100)
t.left(60)
t.forward(100)
go_to(x,y-90)
t.right(60)
t.forward(100)
t.right(60)
t.forward(100)
t.left(60)
eye(x,y)
defeye(x,y):
go_to(x-50,y+130)
t.right(90)
t.forward(50)
go_to(x+40,y+130)
t.forward(50)
t.left(90)
defbig_Circle(size):
t.speed(20)
foriinrange(150):
t.forward(size)
t.right(0.3)
defline(size):
t.speed(20)
t.forward(51*size)
defsmall_Circle(size):
t.speed(20)
foriinrange(210):
t.forward(size)
t.right(0.786)
defheart(x,y,size):
go_to(x,y)
t.left(150)
t.begin_fill()
line(size)
big_Circle(size)
small_Circle(size)
t.left(120)
small_Circle(size)
big_Circle(size)
line(size)
t.end_fill()
defmain():
t.pensize(2)
t.color('red','pink')
head(-120,100,100)
heart(250,-80,1)
go_to(100,-300)
t.write("To:智慧与美貌并存的",move=True,align="left",font=("楷体",20,"normal"))
t.done()
main()
效果图:
到此这篇关于利用Python如何画一颗心、小人发射爱心的文章就介绍到这了,更多相关Python画小人发射爱心内容请搜索毛票票以前的文章或继续浏览下面的相关文章希望大家以后多多支持毛票票!
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。