I have the following code and I am now trying to draw my first initial. My turtle seems to have no color despite naming it to be navy blue. How do I fix this? I need the pen color to be redefined as navy blue when drawing the first initial, but when this code is ran, it draws like it is invisible?
Why is it doing this?
import turtle
def main():
print("Project 1 by Amanda Basant")
main()
def draw_first_initial(turtle):
turtle.color("navy")
turtle.up()
turtle.goto(-200,200)
turtle.left(15)
turtle.forward(30)
turtle.left(180)
turtle.forward(30)
turtle.left(150)
turtle.forward(30)
turtle.left(180)
turtle.forward(15)
turtle.right(75)
turtle.forward(9)
def perform_boxtrot(turtle):
draw_filled_square(turtle,300,"blue")
draw_filled_square(turtle,300,"green")
draw_filled_square(turtle,300,"blue")
draw_filled_square(turtle,300,"green")
def draw_filled_square(turtle,size,color):
turtle.fillcolor(color)
turtle.begin_fill()
for i in range(4):
turtle.forward(size)
turtle.left(90)
turtle.right(90)
turtle.end_fill()
def draw_picture():
window = turtle.Screen()
amanda = turtle.Turtle()
amanda.up()
amanda.goto(0,0)
amanda.down()
perform_boxtrot(amanda)
draw_first_initial(amanda)
draw_picture()
Any help is appreciated!!
CodePudding user response:
The only real issue here is the typo in the function definition. It should be def draw_first_initial
.
The if __name__ == "__main__"
block would be a nice to have.
Original answer:
You're calling main()
before the function is defined.
Instead, delete your main method and try adding this block at the bottom:
if __name__ == "__main__":
print("Project 1 by Amanda Basant")
draw_picture(amanda)
CodePudding user response:
Sample:
from turtle import *
color('red', 'yellow')
begin_fill()
while True:
forward(200)
left(170)
if abs(pos()) < 1:
break
end_fill()
done()