当前位置: 代码网 > it编程>前端脚本>Python > Python画一个五星红旗

Python画一个五星红旗

2024年08月01日 Python 我要评论
t.setup(1500,1000,0,0)#设置窗口大小。t.goto(-400,-160)#将画笔移动到指定位置。t.fillcolor("red")#设置封闭图形的颜色。t.pencolor("yellow")#设置画笔颜色。t.fd(700)#前进700像素。t.fd(450)#前进450像素。t.left(90)#左转90度。t.pensize(2)#设置画笔大小。t.hideturtle()#隐藏画笔。t.pendown()#画笔落下。t.penup()#把画笔抬起。

                                    

python需要安装turtle库
没安装是用不了的

不要问我为什么这么长,拿图比着一个一个代码边敲试出来的能不长ovo
复制下面的代码到python的开发环境idle或者直接复制到pycharm运行

理解透彻后续更多内容关注我

import turtle as t#使用turtle库并简写名称为t
#红旗
t.setup(1500,1000,0,0)#设置窗口大小
t.pensize(2)#设置画笔大小
t.penup()#把画笔抬起
t.hideturtle()#隐藏画笔
t.goto(-400,-160)#将画笔移动到指定位置
t.pendown()#画笔落下
t.pencolor("yellow")#设置画笔颜色
t.fillcolor("red")#设置封闭图形的颜色
t.begin_fill()#开始上色
for i in range(2):#循环结构
    t.fd(700)#前进700像素
    t.left(90)#左转90度
    t.fd(450)#前进450像素
    t.left(90)
t.end_fill()
#大五星
t.pensize(0.5)
t.pencolor("yellow")
t.fillcolor("yellow")
t.penup()
t.goto(-329,183)
t.pendown()
t.hideturtle()
t.begin_fill()
for i in range(1):
    t.fd(45)
    t.left(70)
    t.fd(40)
    t.right(140)
    t.fd(40)
    t.left(70)
    t.fd(45)
    t.right(140)
    t.fd(45)
    t.left(70)
    t.fd(45)
    t.right(140)
    t.fd(45)
    t.left(60)
    t.fd(45)
    t.right(140)
    t.fd(45)
    t.left(72)
    t.fd(45)
t.end_fill()
#第一个小五星
t.pensize(0.5)
t.penup()
t.goto(-165,250)
t.pendown()
t.hideturtle()
t.pencolor("yellow")
t.fillcolor("yellow")
t.begin_fill()
t.right(175)
for q in range(1):
    t.fd(15)
    t.left(70)
    t.fd(15)
    t.right(140)
    t.fd(15)
    t.left(70)
    t.fd(15)
    t.right(140)
    t.fd(15)
    t.left(70)
    t.fd(15)
    t.right(140)
    t.fd(15)
    t.left(60)
    t.fd(15)
    t.right(140)
    t.fd(15)
    t.left(72)
    t.fd(15)
t.end_fill()
#第二个小五星
t.pensize(0.5)
t.penup()
t.goto(-95,195)
t.pendown()
t.hideturtle()
t.pencolor("yellow")
t.fillcolor("yellow")
t.begin_fill()
t.right(235)
for q in range(1):
    t.fd(15)
    t.left(70)
    t.fd(15)
    t.right(140)
    t.fd(15)
    t.left(70)
    t.fd(15)
    t.right(140)
    t.fd(15)
    t.left(70)
    t.fd(15)
    t.right(140)
    t.fd(15)
    t.left(60)
    t.fd(15)
    t.right(140)
    t.fd(15)
    t.left(72)
    t.fd(15)
t.end_fill()
#第三个小五星
t.pensize(0.5)
t.penup()
t.goto(-132,100)
t.pendown()
t.hideturtle()
t.pencolor("yellow")
t.fillcolor("yellow")
t.begin_fill()
t.right(305)
for q in range(1):
    t.fd(15)
    t.left(70)
    t.fd(15)
    t.right(140)
    t.fd(15)
    t.left(70)
    t.fd(15)
    t.right(140)
    t.fd(15)
    t.left(70)
    t.fd(15)
    t.right(140)
    t.fd(15)
    t.left(60)
    t.fd(15)
    t.right(140)
    t.fd(15)
    t.left(72)
    t.fd(15)
t.end_fill()
#第四个小五星
t.pensize(0.5)
t.penup()
t.goto(-145,70)
t.pendown()
t.hideturtle()
t.pencolor("yellow")
t.fillcolor("yellow")
t.begin_fill()
t.right(380)
for q in range(1):
    t.fd(15)
    t.left(70)
    t.fd(15)
    t.right(140)
    t.fd(15)
    t.left(70)
    t.fd(15)
    t.right(140)
    t.fd(15)
    t.left(70)
    t.fd(15)
    t.right(140)
    t.fd(15)
    t.left(60)
    t.fd(15)
    t.right(140)
    t.fd(15)
    t.left(72)
    t.fd(15)
t.end_fill()
t.done()

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com