hello,大家好,我是wangzirui32,今天我们来学习如何使用turtle绘制奥运五环,开始学习吧!
1、代码 1.1 引入所需包 初始化import turtleturtle.hideturtle() # 隐藏绘图小海龟
1.2 画出单个圆函数def draw_a_circle(x, y, color): turtle.penup() # 提笔 turtle.goto(x, y) # 前往x, y处开始绘图 turtle.pensize(5) # 画布粗细为5 turtle.pencolor(color) # 设置画笔颜色 turtle.pendown() # 下笔 turtle.circle(70) # 绘制一个半径为70的圆 turtle.penup() # 提笔
1.3 画出5个圆draw_a_circle(-130, 75, "cyan") # 在-130, 75处绘制颜色为cyan的圆 draw_a_circle(-10, 75, "black") # 在-10, 75处绘制颜色为black的圆 draw_a_circle(110, 75, "red") # 在-110, 75处绘制颜色为red的圆 draw_a_circle(-60, -20, "yellow") # 在-60, -20处绘制颜色为yellow的圆 draw_a_circle(60, -20, "lightgreen") # 在60, -20处绘制颜色为lightgreen的圆 turtle.mainloop() # 持续显示turtle窗口
1.4 完整代码import turtleturtle.hideturtle()turtle.pensize(8)def draw_a_circle(x, y, color): turtle.penup() turtle.goto(x, y) turtle.pensize(5) turtle.pencolor(color) turtle.pendown() turtle.circle(70) turtle.penup()draw_a_circle(-130, 75, "cyan")draw_a_circle(-10, 75, "black")draw_a_circle(110, 75, "red")draw_a_circle(-60, -20, "yellow")draw_a_circle(60, -20, "lightgreen")turtle.mainloop()
2、效果图好了,今天的课程就到这里,我是wangzirui32,喜欢的可以点个收藏和关注,我们下次再见!