Python中用turtle来画中国国旗
2019-07-27 10:02
225 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_37232647/article/details/97486766
之前有看到过有大哥级人物用turtle来画出小猪佩奇,作为刚入门的小白来说,画小猪佩奇还是比较难的,于是就画了个比较简单的(中国国旗)上上手。
在这里呢,我是首先画出了中国国旗的外部矩形边框,采用了2:1的设置来进行,长:宽=400:200,长与宽的设置也可以自己设置,一般都是2:1以及3:2。
import turtle as t t.up()#提笔 t.goto(-325,0)#提笔至(-325,0)象限内 t.down()#落笔 t.begin_fill()# 开始填充 t.fillcolor("red") #填充颜色 t.forward(400)#向前移动400个像素点 t.left(90)#左转90度 t.forward(200) t.left(90) t.forward(400) t.left(90) t.forward(200) t.end_fill()
在外部矩形画好之后,接下里就是开始画里面的大五角星,在画入里面的大五角星可以先进行提笔与落笔等语句,虽然每次这样写很麻烦,要是不写则会从上个点到下个点中间会有一条直线。
#大五角星 t.lt(90) t.up() t.goto(-300,150) t.down() t.right(36) t.forward(25) t.begin_fill()#开始填充颜色 t.fillcolor("yellow") for _ in range(5): #用循环来画出五角星的路径 t.right(72) t.forward(25) t.left(144) t.forward(25) t.end_fill()
继而在画完大五角星之后,转而对最上方小五角星进行画出
#小五角星1 t.up() t.goto(-220,185) t.down() t.right(36) t.forward(10) t.begin_fill() t.fillcolor("yellow") for _ in range(5): t.right(72) t.forward(10) t.left(144) t.forward(10) t.end_fill()
在这里的话,因为每个五角星的角度都是不一样的,所以我就用简单粗暴的方式相对写出了剩余的3个。
#小五角星2 t.up() t.goto(-200, 155) t.down() t.lt(36) t.right(36) t.forward(10) t.begin_fill() t.fillcolor("yellow") for _ in range(5): t.right(72) t.forward(10) t.left(144) t.forward(10) t.end_fill()
#五角星3 t.up() t.goto(-190, 125) t.down() t.right(36) t.forward(10) t.begin_fill()# 开始填充 t.fillcolor("yellow") #填充颜色 for _ in range(5): t.right(72) t.forward(10) t.left(144) t.forward(10) t.end_fill()
#小五角星4 t.up() t.goto(-220, 100) t.down() t.lt(72) t.right(36) t.forward(10) t.begin_fill() t.fillcolor("yellow") for _ in range(5): t.right(72) t.forward(10) t.left(144) t.forward(10) t.end_fill() t.done()
对于初学者的我还是先画画简单的好,以下是我整理部分的turtle语法:
import turtle#导入模块
turtle.forward(x) #向前移动x个像素
turtle.left(x) #左转x度
turtle.pensize(5) # 画笔的粗细
turtle.pencolor(“green”)# 画笔颜色
turtle.begin_fill()# 开始填充
turtle.fillcolor(“red”) #填充颜色
turtle.end_fill() #结束填充
turtle.circle(x) # 画一个半径为x的圆
turtle.speed(x) # 设置画笔速度为x
turtle.setup(x, y) # 设置主窗口的大小为x*y
turtle.colormode(255) # 设置GBK颜色范围为0-255
turtle.seth(90) # 笔的角度为90度
小白第一次写博客,不太有经验,若有错误的地方,请指出一下給。
相关文章推荐
- python 使用turtle画国旗
- Python用Turtle画美国国旗
- Python---turtle模块---日本国旗的绘画
- Python---turtle模块---瑞士国旗的绘画
- Python turtle库绘制中国结
- Python---turtle模块---美国国旗的绘画
- 用Python的turtle模块画国旗
- python turtle库 简单图形-中国结
- 从Python的turtle绘图开始学习图形化程序设计
- python之绘制图形库turtle
- Python基础(三)——turtle模块
- 中国有句俗语叫“三天打鱼两天晒网”。某人从2010年1月1日起开始“三天打鱼两天晒网”, 问这个人在以后的某一天中是“打鱼”还是“晒网”。用C或C++语言/java/python实现程序解决问题
- 解决Ubuntu python 使用turtle显示没有Tkinter模块问题
- canvas绘制中国国旗
- Python3.4 邮件(包含附件与中国)
- Python裸奔也疯狂:批量爬取中国工程院院士信息
- Python,tkinter库与turtle库实现(520,情人节)小礼物
- [Python3爬虫从入门到精通]中国大…
- python学习之输入输出,if,while,for,简单的turtle使用
- Python一日一练18----用turtle写猫和老鼠小游戏