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

本篇文章介绍了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 turtle工具绘制四叶草的实例分享 的全部内容, 来源链接: utcz.com/z/344159.html

回到顶部