初学python时,在海龟绘图看到一幅纪念碑谷的作品,顿时来了兴趣,于是自己画了画,模仿出了类似的效果。

turtle官方文档

import turtle as t

def drawlight(x,y):
    t.penup()
    t.goto(x, y)
    t.pendown()
    t.fillcolor(255,255,255)
    t.begin_fill()
    t.seth(30)
    t.fd(10)
    t.seth(-80)
    t.fd(5)
    t.seth(-150)
    t.fd(10)
    t.seth(80)
    t.fd(5)
    t.end_fill()

t.setup(500, 500)
t.getscreen().colormode(255)
t.pencolor("blue")
t.speed(10)
t.penup()
t.goto(-250, 250)
t.pendown()
#背景填充
t.begin_fill()
t.fillcolor((25,25,112))
for i in range(4):
    t.fd(500)
    t.right(90)
t.end_fill()
#框架搭构
#第一部分
t.penup()
t.goto(-100, -100)
t.pendown()
t.left(90)
t.pencolor(105,54,161)
t.fillcolor(186,85,211)
t.begin_fill()
t.fd(210)
t.right(110)
t.fd(160)
t.right(120)
t.fd(18)
t.right(60)
t.fd(130)
t.left(110)
t.fd(190)
(x1,y1) = (t.xcor(), t.ycor())
t.goto(-100,-100)
t.end_fill()
#time.sleep(5)
#第二部分
t.seth(90)
t.fd(210)
t.fillcolor(138,43,226)
t.begin_fill()
t.right(45)
t.fd(20)
t.right(65)
t.fd(180)
t.right(120)
(x2,y2) = (t.xcor(), t.ycor())
t.fd(190)
t.seth(90)
(x3,y3) = (t.xcor(), t.ycor())
t.fd(20)
t.right(50)
t.fd(146)
t.end_fill()
#第三部分
t.penup()
t.goto(x1, y1)
t.pendown()
t.fillcolor(139,0,139)
t.begin_fill()
t.seth(90)
t.fd(190)
t.right(110)
t.fd(25)
#time.sleep(2)
t.goto(x3, y3)
t.goto(x2, y2)
t.seth(-90)
t.fd(25)
t.goto(x1,y1)
t.end_fill()
#灯
drawlight(-80,60)
drawlight(-80,40)
drawlight(-80,20)
drawlight(-80,0)
drawlight(-80,-20)
#人物
t.pensize(2)
t.seth(60)
t.penup()
t.fd(150)
t.pendown()
t.color("white")
t.begin_fill()
t.fd(30)
t.seth(-60)
t.fd(20)
t.circle(-13,210)
t.end_fill()

#腿
t.penup()
t.seth(0)
t.fd(8)
t.seth(-90)
t.fd(11)
t.pendown()
t.pensize(2)
t.fd(20)
t.seth(-45)
t.pensize(4)
t.fd(8)

t.penup()
t.seth(90)
t.fd(23)
t.seth(0)
t.fd(5)
t.seth(-90)
t.pendown()
t.pensize(2)
t.fd(12)
t.seth(-45)
t.pensize(4)
t.fd(5)

#调制位置
t.penup()
t.seth(90)
t.fd(75)
t.seth(180)
t.fd(8)
t.pendown()

#头
t.begin_fill()
t.pensize(2)
t.circle(15)
t.end_fill()

#调制位置
t.penup()
t.seth(-90)
t.fd(25)
t.pendown()

#帽子
t.begin_fill()
t.speed(1)
t.seth(150)
t.fd(40)
t.right(150)
t.fd(35)
t.end_fill()

#眼睛
t.penup()
t.fd(-3)
t.seth(-90)
t.fd(4)
t.pensize(3)
t.pendown()
t.pencolor("black")
t.seth(30)
t.circle(-6,-180)
#作品名
t.penup()
t.goto(100,200)
t.pendown()
t.pencolor("white")
t.write("纪念碑谷2",font=("方正舒体","20"))
t.hideturtle()
#署名
t.penup()
t.goto(150,-200)
t.pendown()
t.pencolor("black")
t.write("name",font=("微软雅黑","15"))
t.done()

最终的效果为
image

原文地址:http://www.cnblogs.com/coco02/p/16901875.html

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长! 2. 分享目的仅供大家学习和交流,请务用于商业用途! 3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入! 4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解! 5. 如有链接无法下载、失效或广告,请联系管理员处理! 6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需! 7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员! 8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载 声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性