首页 > 文章列表 > python中turtle如何画太阳花?

python中turtle如何画太阳花?

Python turtle
407 2022-08-07

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

1.turtle概念

turtle(海龟)库是turtle绘图体系的python实现,turtle库是一种标准库,是python自带的

turtle(海龟)是一种真实的存在,有一个海龟在窗口的正中心,在画布上游走,走过的轨迹形成了绘制的图形,海龟由程序控制,可改变颜色,宽度等。

turtle.done()的作用:暂停程序,停止画笔绘制,但绘图窗体不关闭,直到用户关闭Python Turtle图形化窗口为止。

2.画笔属性

(1)turtle.pensize():设置画笔的宽度;

(2)turtle.pencolor():没有参数传入,返回当前画笔颜色,传入参数设置画笔颜色,可以是字符串如"green", "red",也可以是RGB 3元组。

(3)turtle.speed(speed):设置画笔移动速度,画笔绘制的速度范围[0,10]整数,数字越大越快。

3.实例

太阳花

# coding=utf-8
 
import turtle
 
import time
 
 
 
# 同时设置pencolor=color1, fillcolor=color2
 
turtle.color("red", "yellow")
 
 
 
turtle.begin_fill()
 
for _ in range(50):
 
turtle.forward(200)
 
turtle.left(170)
 
turtle.end_fill()
 
 
 
turtle.mainloop()