This appears to be the basic model for drawing curved shapes with
turtle. We are, effectively, defining mathematical functions.
from turtle import*
Screen().bgcolor('LightYellow2')
my_t = Turtle()
my_t.color('green')
my_t.speed(1)
my_t.pu()
my_t.goto(0, -100)
my_t.pd()
def draw_leaf():
my_t.begin_fill()
for i in range(50):
my_t.forward(1)
my_t.left(1)
for j in range(75):
my_t.forward(2)
my_t.left(1)
while my_t.xcor() >= 0:
my_t.forward(3)
my_t.left(1)
my_t.end_fill()
draw_leaf()
done()
* * *
from turtle import*
# set up for two turtles that will be drawing the actual leaf.
Screen().bgcolor('LightYellow2')
my_t = Turtle()
my_t.color('green')
my_t.fillcolor('pale green')
my_t.speed(1)
my_t.pu()
my_t.goto(0, -100)
my_t.pd()
my_t2 = Turtle()
my_t2.color('green')
my_t2.fillcolor('pale green')
my_t2.speed(1)
my_t2.pu()
my_t2.goto(0, -100)
my_t2.setheading(180)
my_t2.pd()
# right side of leaf
def draw_leaf1():
my_t.begin_fill()
for i in range(50):
my_t.forward(1)
my_t.left(1)
for j in range(75):
my_t.forward(2)
my_t.left(1)
while my_t.xcor() >= 0:
my_t.forward(3)
my_t.left(1)
my_t.end_fill()
# left side of leaf
def draw_leaf2():
my_t2.begin_fill()
for i in range(50):
my_t2.forward(1)
my_t2.right(1)
for j in range(75):
my_t2.forward(2)
my_t2.right(1)
while my_t2.xcor() <= 0:
my_t2.forward(3)
my_t2.right(1)
my_t2.end_fill()
# grey line.. need to define T3 within function so that it will be on top.
def draw_leaf3():
global my_t3
my_t3 = Turtle()
my_t3.color('grey68')
my_t3.pensize(3)
my_t3.pu()
my_t3.goto(0, -125)
my_t3.setheading(90)
my_t3.pd()
my_t3.forward(232)
#function calls, hide the turtle, keep the window open
draw_leaf1()
draw_leaf2()
draw_leaf3()
my_t.hideturtle()
my_t2.hideturtle()
my_t3.hideturtle()
done()
No comments:
Post a Comment