网络编程
位置:首页>> 网络编程>> Python编程>> python使用turtle库绘制奥运五环

python使用turtle库绘制奥运五环

作者:lwtyh  发布时间:2021-06-21 04:22:44 

标签:python,奥运五环,turtle库

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

效果图:

python使用turtle库绘制奥运五环


#奥运五环
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语言的标准之一

标准库:python使用turtle库绘制奥运五环

第三方库:python使用turtle库绘制奥运五环

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

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

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

这些都可以用python绘制出来

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

位置关系

python使用turtle库绘制奥运五环

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

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

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

python使用turtle库绘制奥运五环

python使用turtle库绘制奥运五环

python使用turtle库绘制奥运五环

python使用turtle库绘制奥运五环

来源:https://www.cnblogs.com/lwtyh/p/12348135.html

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com