这篇文章将为大家详细讲解有关python turtle工具怎么绘制四叶草,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
代码如下
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主要应用于:1、Web开发;2、数据科学研究;3、网络爬虫;4、嵌入式应用开发;5、游戏开发;6、桌面应用开发。
关于“python turtle工具怎么绘制四叶草”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。