Skip to content
Sign UpLog In
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
1

How do you draw a triangle in pyhton turtle using for loops?

AhmadShaheerSha
AhmadShaheerSha

import turtle
def drawing_circle():
bob.color("Green")
bob.speed(1000)
bob.shape("turtle")
bob.circle(59)
window = turtle.Screen()
bob = turtle.Turtle()
bob.goto(50,-30)
bob.pendown()
drawing_circle()

turtle.color("Green")
turtle.fillcolor("Yellow")
turtle.speed(1000)
def recursive_triangles(length,depth):
turtle.begin_fill()
if depth == 0:
for i in range(0,3):
turtle.forward(length)
turtle.left(120)
else:
recursive_triangles(length/2, depth-1)
turtle.forward(length/2)
recursive_triangles(length/2,depth-1)
turtle.backward(length/2)
turtle.left(60)
turtle.forward(length/2)
turtle.right(60)
recursive_triangles(length/2, depth-1)
turtle.left(60)
turtle.backward(length/2)
turtle.right(60)
turtle.end_fill()
window = turtle.Screen()
t = turtle.Turtle()
recursive_triangles(100,2)

So this is my code but how do I use for loops to make this more efficient? Also is there a way to put the two functions together and make one function?

3 years ago
You are viewing a single comment. View All
2