Turtle简介
Turtle库是Python语言中广泛使用的图像绘制库,可以绘制图形,非常适合指导儿童学习编程。
玫瑰效果展示
画玫瑰代码
from turtle import *
import turtle
from math import *
import time
def draw_flower_base():
fillcolor("red")
begin_fill()
circle(10, 180)
circle(25, 110)
left(50)
circle(60, 45)
circle(20, 170)
right(24)
fd(30)
left(10)
circle(30, 110)
fd(20)
left(40)
circle(90, 70)
circle(30, 150)
right(30)
fd(15)
circle(80, 90)
left(15)
fd(45)
right(165)
fd(20)
left(155)
circle(150, 80)
left(50)
circle(150, 90)
end_fill()
def draw_flower_petal():
# Petal 1
left(150)
circle(-90, 70)
left(20)
circle(75, 105)
setheading(60)
circle(80, 98)
circle(-90, 40)
# Petal 2
left(180)
circle(90, 40)
circle(-80, 98)
setheading(-83)
def draw_leaves():
fd(30)
left(90)
fd(25)
left(45)
fillcolor("green")
begin_fill()
circle(-80, 90)
right(90)
circle(-80, 90)
end_fill()
right(135)
fd(60)
left(180)
fd(85)
left(90)
fd(80)
# Leaves 2
right(90)
right(45)
fillcolor("green")
begin_fill()
circle(80, 90)
left(90)
circle(80, 90)
end_fill()
left(135)
fd(60)
left(180)
fd(60)
right(90)
circle(200, 60)
def draw_flower(x,y):
setpos(x, y)
pendown()
draw_flower_base()
draw_flower_petal()
draw_leaves()
def main():
Screen().setup(width=800, height=600)
draw_flower(-120, 130)
penup();
home()
draw_flower(45, 150)
penup();
home()
draw_flower(180, 120)
done()
if __name__ == "__main__":
hideturtle()
up()
goto(-260, 270)
write("今天头条-cloudcoder出品", align='left', font=('fangsong', 14, 'normal'))
goto(0, 0)
showturtle()
speed(30)
main()