首页 > 编程语言 >Python绘图之纪念碑谷

Python绘图之纪念碑谷

时间:2022-11-18 00:11:24浏览次数:76  
标签:penup Python seth pendown 纪念碑 fd 90 绘图 fill

初学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

标签:penup,Python,seth,pendown,纪念碑,fd,90,绘图,fill
From: https://www.cnblogs.com/coco02/p/16901875.html

相关文章

  • Python爬虫之旅游景点评论
    目录爬取景点评论准备工作获取HTML页面解析处理worldcloudreference:爬取携程景点评论数据本博客记录一个爬取携程景点评论并制作词云的例子,并且可以很轻易地拓展到多个......
  • Python Pickle 与 JSON
    1.PythonPickle和JSON之间的区别很全面很棒的解释。2.一篇使用说明:https://janakiev.com/blog/python-pickle-json/3.mmdetection3d中的说明https://githu......
  • 排序算法Python
    冒泡排序defbubbleSort(nums):iflen(nums)<=1:returnnumsforiinrange(len(nums)-1):forjinrange(len(nums)-i-1):......
  • python基础语法知识
    1、多组输入没有结束标志的两种表示形式#method1:try:whileTrue:#代码exceptEOFError:pass #method2:whileTrue:try:#代码......
  • python-单例-笔记
    目标单例设计模式​​__new__​​ 方法Python中的单例01.单例设计模式设计模式设计模式 是 前人工作的总结和提炼,通常,被人们广泛流传的设计模式都是针对 某一特定问题......
  • python-异常-笔记
    目标异常的概念捕获异常异常的传递抛出异常01.异常的概念程序在运行时,如果 ​​Python解释器​​ 遇到 到一个错误,会停止程序的执行,并且提示一些错误信息,这就是 异常......
  • python-模块和包-笔记
    目标模块包发布模块01.模块1.1模块的概念模块是Python程序架构的一个核心概念每一个以扩展名 ​​py​​ 结尾的 ​​Python​​ 源代码文件都是一个 模块模块名 ......
  • python-文件-笔记
    目标文件的概念文件的基本操作文件/文件夹的常用操作文本文件的编码方式01.文件的概念1.1文件的概念和作用计算机的 文件,就是存储在某种 长期储存设备 上的一段 数据......
  • python-eval 函数-笔记
    ​​eval()​​ 函数十分强大—— 将字符串 当成 有效的表达式 来求值并 返回计算结果#基本的数学计算In[1]:eval("1+1")Out[1]:2#字符串重复In[2]:eval("'*'......
  • 20221117-python-条件判断
    1.浅拷贝与深拷贝        2.分支语句   ......