当前位置:首页 » 《关于电脑》 » 正文

Python编写五星红旗

22 人参与  2024年11月11日 11:22  分类 : 《关于电脑》  评论

点击全文阅读


1.导入海龟库

import turtle

2.绘制旗面

##绘制旗面turtle.penup()turtle.goto(-300,-200)turtle.pendown()turtle.color("red")turtle.begin_fill()turtle.forward(600)turtle.left(90)turtle.forward(400)turtle.left(90)turtle.forward(600)turtle.left(90)turtle.forward(400)turtle.left(90)turtle.end_fill()

3.绘制大五角星

turtle.color("gold")turtle.begin_fill()turtle.penup()turtle.goto(-260,120)turtle.pendown()for i in range(5):    turtle.forward(120)    turtle.right(144)turtle.end_fill()

4.绘制第一个小五角星

turtle.color("gold")turtle.begin_fill()turtle.penup()turtle.goto(-120,160)turtle.pendown()for i in range(5):    turtle.forward(40)    turtle.right(144)turtle.end_fill()

5.绘制第二个小五角星

##第二个小五角星turtle.color("gold")turtle.begin_fill()turtle.penup()turtle.goto(-80,120)turtle.pendown()for i in range(5):    turtle.forward(40)    turtle.right(144)turtle.end_fill()

6.绘制第三个小五角星

turtle.color("gold")turtle.begin_fill()turtle.penup()turtle.goto(-80,60)turtle.pendown()for i in range(5):    turtle.forward(40)    turtle.right(144)turtle.end_fill()

7.绘制第四个小五角星

turtle.color("gold")turtle.begin_fill()turtle.penup()turtle.goto(-120,20)turtle.pendown()for i in range(5):    turtle.forward(40)    turtle.right(144)turtle.end_fill()

8.隐藏画笔

turtle.hideturtle()turtle.done()

9.完整代码

import turtle##绘制旗面turtle.penup()turtle.goto(-300,-200)turtle.pendown()turtle.color("red")turtle.begin_fill()turtle.forward(600)turtle.left(90)turtle.forward(400)turtle.left(90)turtle.forward(600)turtle.left(90)turtle.forward(400)turtle.left(90)turtle.end_fill()##大五角星turtle.color("gold")turtle.begin_fill()turtle.penup()turtle.goto(-260,120)turtle.pendown()for i in range(5):    turtle.forward(120)    turtle.right(144)turtle.end_fill()##第一个小五角星turtle.color("gold")turtle.begin_fill()turtle.penup()turtle.goto(-120,160)turtle.pendown()for i in range(5):    turtle.forward(40)    turtle.right(144)turtle.end_fill()##第二个小五角星turtle.color("gold")turtle.begin_fill()turtle.penup()turtle.goto(-80,120)turtle.pendown()for i in range(5):    turtle.forward(40)    turtle.right(144)turtle.end_fill()##第三个小五角星turtle.color("gold")turtle.begin_fill()turtle.penup()turtle.goto(-80,60)turtle.pendown()for i in range(5):    turtle.forward(40)    turtle.right(144)turtle.end_fill()##第四个小五角星turtle.color("gold")turtle.begin_fill()turtle.penup()turtle.goto(-120,20)turtle.pendown()for i in range(5):    turtle.forward(40)    turtle.right(144)turtle.end_fill()turtle.haideturtle()turtle.done()


点击全文阅读


本文链接:http://zhangshiyu.com/post/184497.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1