您的位置:首页 > 编程语言 > Python开发

python turtle工具绘制四叶草的实例分享

2020-03-17 12:04 591 查看

本篇文章介绍了python使用turtle库绘制四叶草的方法,代码很简单,希望对学习python的朋友有帮助。

import turtle
import time
turtle.setup(650.,350,200,200)
turtle.pendown()
turtle.pensize(10)
turtle.pencolor('green')

#四叶草
def draw_clover(radius,rotate):   #参数radius控制叶子的大小,rotate控制叶子的旋转
for i in range(4):
direction = i*90
turtle.seth(60+direction+rotate) #控制叶子根部的角度为60度
# turtle.fd(2*radius*pow(2,1/2)) #控制叶子根部的角度为90度
turtle.fd(4*radius)
for j in range(2):
turtle.seth(90+direction+rotate)
turtle.circle(radius,180)
turtle.seth(-60+direction+rotate)
turtle.fd(4*radius)
turtle.seth(-90)
turtle.fd(6*radius)

draw_clover(30,45)
time.sleep(5)

内容扩展

import turtle

def draw_shapes():

window = turtle.Screen()

window.bgcolor("red")

flower = turtle.Turtle()

flower.speed(10)

flower.shape("arrow")

flower.right(45)

for i in range(1,37):

for j in range(1,5):

draw_circle(flower,i,"green")

flower.left(90)

flower.right(45)

flower.color("green")

flower.forward(500)

window.exitonclick()

def draw_circle(circle,radius,color):

circle.color(color)

circle.circle(radius)

draw_shapes()

以上就是python绘图四叶草的详细内容,感谢大家的学习和对脚本之家的支持。

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python 绘制四叶草