Skip to content

Instantly share code, notes, and snippets.

@Shurastei
Created December 18, 2020 02:16
Show Gist options
  • Save Shurastei/c9c8c27734d2e04a96386e7279a958c1 to your computer and use it in GitHub Desktop.
Save Shurastei/c9c8c27734d2e04a96386e7279a958c1 to your computer and use it in GitHub Desktop.
Tartaruguinha fractando uma arvorezinha
import turtle
turtle.shape("turtle")
turtle.speed(speed=1)
MINIMUM_BRANCH_LENGTH = 5
def build_tree(t, branch_length, shorten_by, angle):
if branch_length > MINIMUM_BRANCH_LENGTH:
t.forward(branch_length)
new_length = branch_length - shorten_by
t.left(angle)
build_tree(t, new_length, shorten_by, angle)
t.right(angle * 2)
build_tree(t, new_length, shorten_by, angle)
t.left(angle)
t.backward(branch_length)
tree = turtle.Turtle()
tree.hideturtle()
tree.setheading(90)
tree.color('green')
build_tree(tree, 50, 5, 30)
turtle.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment