python奥运五环 python使用turtle库绘制奥运五环

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

python奥运五环 python使用turtle库绘制奥运五环

lwtyh   2021-04-21 我要评论

Turtle库是Python语言中一个很流行的绘制图像的函数库,想象一个小乌龟,在一个横轴为x、纵轴为y的坐标系原点,(0,0)位置开始,它根据一组函数指令的控制,在这个平面坐标系中移动,从而在它爬行的路径上绘制了图形。

效果图:

#奥运五环
import turtle
turtle.setup(1.0,1.0) #设置窗口大小
turtle.title("奥运五环")
#蓝圆
turtle.penup()
turtle.right(90)
turtle.forward(-50)
turtle.left(90)
turtle.forward(-200)
turtle.pendown()
turtle.pensize(10)
turtle.color("blue")
turtle.circle(100)
#黑圆
turtle.penup()
turtle.forward(250)
turtle.pendown()
turtle.pensize(10)
turtle.color("black")
turtle.circle(100)
#红圆
turtle.penup()
turtle.forward(250)
turtle.pendown()
turtle.pensize(10)
turtle.color("red")
turtle.circle(100)
#黄圆
turtle.penup()
turtle.forward(-275)
turtle.right(-90)
turtle.pendown()
turtle.pensize(10)
turtle.color("yellow")
turtle.circle(100)
#绿圆
turtle.penup()
turtle.left(-90)
turtle.forward(50)
turtle.right(90)
turtle.pendown()
turtle.pensize(10)
turtle.color("green")
turtle.circle(100)

下面看下python中turtle库的使用

turtle也叫海龟,是turtle绘图体系的python实现

turtle绘图体系:1969年诞生,是主要用于程序设计入门

turtle库是python语言的标准之一

标准库:

第三方库:

库:Library,包Package,模块Module,功能各不相同,但统称为模块

turtle库的原理:有一只海龟,在窗体正中心,在画布上游走,走过的轨迹形成了绘制的图形,海龟由程序控制,可以变换颜色,改变宽度等。。。

这些都可以用python绘制出来

turyle绘图窗体的布置,使用的最小绘图单位是像素

位置关系

turtle.setup()函数设置窗体大小及位置;参数是高度,宽度,起始点的坐标,

四个参数,后两个参数是可选的

在绘图的时候setup()函数不是必须的,当需要设置起始点位置是采用

总结

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们