Python练习---turtle绘图之绘制天安门

1.绘制天安门效果

在这里插入图片描述
代码实现:

import turtle as t

t.hideturtle()
t.setup(width=0.9,height=0.9,startx=None,starty=None)
t.speed(5)
t.pensize(1)
t.setx(0)
t.sety(0)

###base###
t.begin_fill()
t.fillcolor(0.8705,0.0784,0.0784)
t.goto(-250,0)
t.goto(-223.55,150)
t.goto(223.55,150)
t.goto(250,0)
t.goto(0,0)
t.end_fill()

##door1#
t.begin_fill()
t.fillcolor("black")
t.goto(20,0)
t.goto(20,40)
t.right(270)
t.circle(20,180)
t.goto(-20,0)
t.goto(0,0)
t.end_fill()

##door2##
t.begin_fill()
t.fillcolor("black")
t.right(90)
t.goto(-50,0)
t.goto(-50,30)
t.right(90)
t.circle(15,180)
t.goto(-80,0)
t.goto(0,0)
t.end_fill()

##door3##
t.begin_fill()
t.fillcolor("black")
t.right(90)
t.goto(-105,0)
t.goto(-105,30)
t.right(90)
t.circle(15,180)
t.goto(-135,0)
t.goto(0,0)
t.end_fill()

##door4##
t.begin_fill()
t.fillcolor("black")
t.right(90)
t.goto(80,0)
t.goto(80,30)
t.right(90)
t.circle(15,180)
t.goto(50,0)
t.goto(0,0)
t.end_fill()

##door5##
t.begin_fill()
t.fillcolor("black")
t.right(90)
t.goto(135,0)
t.goto(135,30)
t.right(90)
t.circle(15,180)
t.goto(105,0)
t.goto(0,0)
t.end_fill()

##under##
t.penup()
t.goto(-249.12,5)
t.pendown()
t.begin_fill()
t.fillcolor("yellow")
t.goto(-249.12,5)
t.goto(249.12,5)
t.goto(250,0)
t.goto(-250,0)
t.goto(-249.12,5)
t.end_fill()

##up##
t.penup()
t.goto(-224.43,145)
t.pendown()
t.begin_fill()
t.fillcolor("yellow")
t.goto(224.43,145)
t.goto(223.55,150)
t.goto(-223.55,150)
t.end_fill()

##leftword##
t.penup()
t.fillcolor(0.9372,0.9294,0.9294)
t.goto(-180,140)
t.pendown()
t.begin_fill()
t.goto(-60,140)
t.goto(-60,120)
t.goto(-180,120)
t.goto(-180,140)
t.goto(-180,120)
t.end_fill()
t.penup()
t.fillcolor(0.929,0.180,0.180)
t.goto(-177,137)
t.pendown()
t.begin_fill()
t.goto(-63,137)
t.goto(-63,123)
t.goto(-177,123)
t.goto(-177,137)
t.end_fill()
t.penup()
t.goto(-177,123)
t.pendown()
t.color("white")
t.write("中华人民共和国万岁",align="left",font=("华文中宋","10","normal"))
t.color("black")

##rightword##
t.penup()
t.fillcolor(0.9372,0.9294,0.9294)
t.goto(180,140)
t.pendown()
t.begin_fill()
t.goto(60,140)
t.goto(60,120)
t.goto(180,120)
t.goto(180,140)
t.goto(180,120)
t.end_fill()
t.penup()
t.fillcolor(0.929,0.180,0.180)
t.goto(177,137)
t.pendown()
t.begin_fill()
t.goto(63,137)
t.goto(63,123)
t.goto(177,123)
t.goto(177,137)
t.end_fill()
t.penup()
t.goto(63,123)
t.pendown()
t.color("white")
t.write("世界人民大团结万岁",align="left",font=("华文中宋","10","normal"))
t.color("black")

##face##
t.penup()
t.goto(-25,140)
t.pendown()
t.begin_fill()
t.fillcolor(0.9647,0.71764,0.04313)
t.goto(25,140)
t.goto(25,80)
t.goto(-25,80)
t.goto(-25,140)
t.end_fill()
t.penup()
t.goto(-23,138)
t.pendown()
t.begin_fill()
t.fillcolor(0.9686,0.8078,0.36862)
t.goto(23,138)
t.goto(23,83)
t.goto(-23,83)
t.goto(-23,137)
t.end_fill()

###floor##
t.penup()
t.fillcolor(0.8705,0.0784,0.0784)
t.goto(0,151)
t.pendown()
t.begin_fill()
t.goto(160,151)
t.goto(160,185.63)
t.goto(-160,185.63)
t.goto(-160,151)
t.goto(0,151)
t.end_fill()
##on door1##
t.penup()
t.goto(-155,150)
t.fillcolor(0.6705,0.0588,0.0588)
t.pendown()
t.left(90)
t.begin_fill()
t.left(90)
t.fd(25)
t.right(90)
t.circle(5,90)
t.right(90)
t.fd(15)
t.right(90)
t.circle(5,90)
t.right(90)
t.fd(25)
t.right(90)
t.fd(25)
t.end_fill()
t.penup()
t.fillcolor("yellow")
t.begin_fill()
t.goto(-147,180)
t.pendown()
t.left(180)
for i in range(2):
    t.fd(9)
    t.right(90)
    t.fd(2)
    t.right(90)
t.end_fill()
###lantern##
t.penup()
t.goto(-135,172)
t.pendown()
t.fillcolor(0.8705,0.0784,0.0784)
t.begin_fill()
t.setheading(90)
for k in range(2):
    len=0.2
    for i in range(60):
       if i < 30:
           len +=0.01
       if i >30:
           len -=0.01
       t.fd(len)
       t.left(3)
t.end_fill()
t.penup()
t.goto(-147,165)
t.fillcolor("yellow")
t.pendown()
t.begin_fill()
t.right(90)
for i in range(2):
    t.fd(8)
    t.right(90)
    t.fd(10)
    t.right(90)
t.end_fill()

##on door2##
t.penup()
t.fillcolor(0.6705,0.0588,0.0588)
t.begin_fill()
t.goto(-110,150)
t.pendown()
t.left(90)
t.fd(25)
t.right(90)
t.circle(5,90)
t.right(90)
t.fd(15)
t.right(90)
t.circle(5,90)
t.right(90)
t.fd(25)
t.right(90)
t.fd(25)
t.end_fill()
t.penup()
t.fillcolor("yellow")
t.begin_fill()
t.goto(-102,180)
t.pendown()
t.left(180)
for i in range(2):
    t.fd(9)
    t.right(90)
    t.fd(2)
    t.right(90)
t.end_fill()
###lantern##
t.penup()
t.goto(-90,172)
t.pendown()
t.fillcolor(0.8705,0.0784,0.0784)
t.begin_fill()
t.setheading(90)
for k in range(2):
    len=0.2
    for i in range(60):
       if i < 30:
           len +=0.01
       if i >30:
           len -=0.01
       t.fd(len)
       t.left(3)
t.end_fill()
t.penup()
t.goto(-102,165)
t.fillcolor("yellow")
t.pendown()
t.begin_fill()
t.right(90)
for i in range(2):
    t.fd(8)
    t.right(90)
    t.fd(10)
    t.right(90)
t.end_fill()

##on door3##
t.penup()
t.fillcolor(0.6705,0.0588,0.0588)
t.goto(-65,150)
t.pendown()
t.begin_fill()
t.left(90)
t.fd(25)
t.right(90)
t.circle(5,90)
t.right(90)
t.fd(15)
t.right(90)
t.circle(5,90)
t.right(90)
t.fd(25)
t.right(90)
t.fd(25)
t.end_fill()
t.penup()
t.fillcolor("yellow")
t.begin_fill()
t.goto(-56.5,180)
t.pendown()
t.left(180)
for i in range(2):
    t.fd(9)
    t.right(90)
    t.fd(2)
    t.right(90)
t.end_fill()
###lantern##
t.penup()
t.goto(-45,172)
t.pendown()
t.fillcolor(0.8705,0.0784,0.0784)
t.begin_fill()
t.setheading(90)
for k in range(2):
    len=0.2
    for i in range(60):
       if i < 30:
           len +=0.01
       if i >30:
           len -=0.01
       t.fd(len)
       t.left(3)
t.end_fill()
t.penup()
t.goto(-56.5,165)
t.fillcolor("yellow")
t.pendown()
t.begin_fill()
t.right(90)
for i in range(2):
    t.fd(8)
    t.right(90)
    t.fd(10)
    t.right(90)
t.end_fill()

###door 4##
t.penup()
t.fillcolor(0.6705,0.0588,0.0588)
t.goto(-20,150)
t.pendown()
t.begin_fill()
t.left(90)
t.fd(25)
t.right(90)
t.circle(5,90)
t.right(90)
t.fd(30)
t.right(90)
t.circle(5,90)
t.right(90)
t.fd(25)
t.right(90)
t.fd(25)
t.end_fill()

##on door5##
t.penup()
t.fillcolor(0.6705,0.0588,0.0588)
t.pendown()
t.begin_fill()
t.goto(130,150)
t.right(90)
t.fd(25)
t.right(90)
t.circle(5,90)
t.right(90)
t.fd(15)
t.right(90)
t.circle(5,90)
t.right(90)
t.fd(25)
t.right(90)
t.fd(25)
t.end_fill()
t.penup()
t.fillcolor("yellow")
t.begin_fill()
t.goto(138.5,180)
t.pendown()
t.left(180)
for i in range(2):
    t.fd(9)
    t.right(90)
    t.fd(2)
    t.right(90)
t.end_fill()
###lantern##
t.penup()
t.goto(150,172)
t.pendown()
t.fillcolor(0.8705,0.0784,0.0784)
t.begin_fill()
t.setheading(90)
for k in range(2):
    len=0.2
    for i in range(60):
       if i < 30:
           len +=0.01
       if i >30:
           len -=0.01
       t.fd(len)
       t.left(3)
t.end_fill()
t.penup()
t.goto(138.5,165)
t.fillcolor("yellow")
t.pendown()
t.begin_fill()
t.right(90)
for i in range(2):
    t.fd(8)
    t.right(90)
    t.fd(10)
    t.right(90)
t.end_fill()

##on door4##
t.penup()
t.fillcolor(0.6705,0.0588,0.0588)
t.begin_fill()
t.goto(85,150)
t.pendown()
t.left(90)
t.fd(25)
t.right(90)
t.circle(5,90)
t.right(90)
t.fd(15)
t.right(90)
t.circle(5,90)
t.right(90)
t.fd(25)
t.right(90)
t.fd(25)
t.end_fill()
t.penup()
t.fillcolor("yellow")
t.begin_fill()
t.goto(93.5,180)
t.pendown()
t.left(180)
for i in range(2):
    t.fd(9)
    t.right(90)
    t.fd(2)
    t.right(90)
t.end_fill()
###lantern##
t.penup()
t.goto(105,172)
t.pendown()
t.fillcolor(0.8705,0.0784,0.0784)
t.begin_fill()
t.setheading(90)
for k in range(2):
    len=0.2
    for i in range(60):
       if i < 30:
           len +=0.01
       if i >30:
           len -=0.01
       t.fd(len)
       t.left(3)
t.end_fill()
t.penup()
t.goto(93.5,165)
t.fillcolor("yellow")
t.pendown()
t.begin_fill()
t.right(90)
for i in range(2):
    t.fd(8)
    t.right(90)
    t.fd(10)
    t.right(90)
t.end_fill()
##on door6##
t.penup()
t.fillcolor(0.6705,0.0588,0.0588)
t.goto(40,150)
t.pendown()
t.begin_fill()
t.left(90)
t.fd(25)
t.right(90)
t.circle(5,90)
t.right(90)
t.fd(15)
t.right(90)
t.circle(5,90)
t.right(90)
t.fd(25)
t.right(90)
t.fd(25)
t.end_fill()
t.penup()
t.fillcolor("yellow")
t.begin_fill()
t.goto(48.5,180)
t.pendown()
t.left(180)
for i in range(2):
    t.fd(9)
    t.right(90)
    t.fd(2)
    t.right(90)
t.end_fill()
###lantern##
t.penup()
t.goto(60,172)
t.pendown()
t.fillcolor(0.8705,0.0784,0.0784)
t.begin_fill()
t.setheading(90)
for k in range(2):
    len=0.2
    for i in range(60):
       if i < 30:
           len +=0.01
       if i >30:
           len -=0.01
       t.fd(len)
       t.left(3)
t.end_fill()
t.penup()
t.goto(48.5,165)
t.fillcolor("yellow")
t.pendown()
t.begin_fill()
t.right(90)
for i in range(2):
    t.fd(8)
    t.right(90)
    t.fd(10)
    t.right(90)
t.end_fill()

###floor up##
t.penup()
t.goto(0,185)
t.pendown()
t.fillcolor(0.6705,0.0588,0.0588)
t.begin_fill()
t.goto(180,185)
t.goto(190,195)
t.goto(-190,195)
t.goto(-180,185)
t.goto(0,185)
t.end_fill()

##floor upup##
t.penup()
t.goto(0,195)
t.begin_fill()
t.fillcolor(0.9568,0.53333,0.2470)
t.pendown()
t.goto(190,195)
t.goto(190,195+14.7)
t.goto(187.73,195+11.94)
t.goto(147.88,195+15.42)
t.goto(-147.88,195+15.42)
t.goto(-187.73,195+11.94)
t.goto(-190,195+14.7)
t.goto(-190,195)
t.goto(0,195)
t.end_fill()

##floor2 under###
t.penup()
t.goto(0,211)
t.pendown()
t.fillcolor(0.4705,0.8431,0.4117)
t.begin_fill()
t.goto(130,211)
t.goto(130,220)
t.goto(-130,220)
t.goto(-130,211)
t.goto(0,211)
t.end_fill()
##floor2##
t.penup()
t.goto(0,221)
t.pendown()
t.fillcolor(0.6705,0.0588,0.0588)
t.begin_fill()
t.goto(140,221)
t.goto(150,230)
t.goto(-150,230)
t.goto(-140,221)
t.goto(0,221)
t.end_fill()

##country##
t.penup()
t.goto(0,206.5)
t.fillcolor(0.9803,0.9490,0.03137)
t.pendown()
t.begin_fill()
t.circle(8,360)
t.end_fill()
t.penup()
t.goto(0,208)
t.fillcolor(0.6705,0.0588,0.0588)
t.pendown()
t.begin_fill()
t.circle(6,360)
t.end_fill()
##floor2 up##
t.penup()
t.goto(0,230)
t.begin_fill()
t.fillcolor(0.9568,0.53333,0.2470)
t.pendown()
t.goto(150,230)
t.goto(150,240)
t.goto(130.08,242.37)
t.goto(130.08,277.37)
t.goto(127.28,273.77)
t.goto(124.23,150+125.51)
t.goto(121.5,265.23)
t.goto(-121.5,265.23)
t.goto(-124.23,150+125.51)
t.goto(-127.28,273.77)
t.goto(-130.08,277.37)
t.goto(-130.08,242.37)
t.goto(-150,240)
t.goto(-150,230)
t.goto(0,230)
t.end_fill()

t.exitonclick()
  • 4
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,以下是绘制卡通库洛米的 Python 代码: ```python import turtle # 设置布大小和背景色 turtle.setup(800, 800) turtle.bgcolor("#F8F8F8") # 定义笔颜色和线宽 turtle.pensize(4) turtle.pencolor("#000000") # 绘制库洛米的头和脸 turtle.penup() turtle.goto(0, -200) turtle.pendown() turtle.begin_fill() turtle.circle(200) turtle.end_fill() # 绘制库洛米的眼睛 turtle.penup() turtle.goto(-80, 80) turtle.pendown() turtle.begin_fill() turtle.circle(50) turtle.end_fill() turtle.penup() turtle.goto(-80, 80) turtle.pendown() turtle.begin_fill() turtle.circle(30) turtle.end_fill() turtle.penup() turtle.goto(80, 80) turtle.pendown() turtle.begin_fill() turtle.circle(50) turtle.end_fill() turtle.penup() turtle.goto(80, 80) turtle.pendown() turtle.begin_fill() turtle.circle(30) turtle.end_fill() # 绘制库洛米的嘴巴 turtle.penup() turtle.goto(-100, -20) turtle.pendown() turtle.right(60) turtle.circle(100, 120) # 绘制库洛米的衣服 turtle.penup() turtle.goto(0, -200) turtle.pendown() turtle.begin_fill() turtle.goto(-150, -400) turtle.goto(150, -400) turtle.goto(0, -200) turtle.end_fill() # 绘制库洛米的领带 turtle.penup() turtle.goto(0, -120) turtle.pendown() turtle.begin_fill() turtle.goto(-50, -170) turtle.goto(50, -170) turtle.goto(0, -120) turtle.end_fill() # 绘制库洛米的手 turtle.penup() turtle.goto(-150, -400) turtle.pendown() turtle.right(30) turtle.begin_fill() turtle.goto(-250, -500) turtle.goto(-200, -600) turtle.goto(-150, -400) turtle.end_fill() turtle.penup() turtle.goto(150, -400) turtle.pendown() turtle.left(60) turtle.begin_fill() turtle.goto(250, -500) turtle.goto(200, -600) turtle.goto(150, -400) turtle.end_fill() # 绘制库洛米的脚 turtle.penup() turtle.goto(-70, -500) turtle.pendown() turtle.right(30) turtle.begin_fill() turtle.goto(-120, -700) turtle.goto(-70, -700) turtle.goto(-70, -500) turtle.end_fill() turtle.penup() turtle.goto(70, -500) turtle.pendown() turtle.left(60) turtle.begin_fill() turtle.goto(120, -700) turtle.goto(70, -700) turtle.goto(70, -500) turtle.end_fill() # 隐藏turtle.hideturtle() # 显示绘图窗口 turtle.done() ``` 运行代码后,会弹出一个绘图窗口,显示出卡通库洛米的图像。如果需要保存图像,可以使用 `turtle.getcanvas().postscript(file="filename.eps")` 命令将图像保存为 EPS 格式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

明月醉窗台

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值