当前位置:首页 » python教程 » 正文

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

看: 1710次  时间:2020-08-15  分类 : python教程

本篇文章介绍了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博客的支持。

<< 上一篇 下一篇 >>

搜索

推荐资源

  Powered By python教程网   鲁ICP备18013710号
python博客 - 小白学python最友好的网站!