Rename files, add headers, fix typos in 13
This commit is contained in:
parent
a6b4a427e0
commit
954069159a
8 changed files with 31 additions and 2 deletions
53
thinkcspy/Chapter-16-Exercises/Problem3_tree.py
Normal file
53
thinkcspy/Chapter-16-Exercises/Problem3_tree.py
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
# Runestone.Academy thinkcspy course
|
||||
# Chapter 16
|
||||
# Problem 3
|
||||
|
||||
import turtle
|
||||
import random
|
||||
|
||||
def color(branchlen, t):
|
||||
t.pensize(branchlen/5)
|
||||
if branchlen < 15:
|
||||
t.color("green")
|
||||
else:
|
||||
t.color("brown")
|
||||
|
||||
|
||||
def getAngle():
|
||||
return random.randrange(15, 46)
|
||||
|
||||
|
||||
def getLen(t):
|
||||
return random.randrange(5, 15)
|
||||
|
||||
|
||||
def tree(branchLen,t):
|
||||
if branchLen > 5:
|
||||
color(branchLen, t)
|
||||
t.forward(branchLen)
|
||||
angle = getAngle()
|
||||
t.right(angle)
|
||||
tree(branchLen-getLen(t),t)
|
||||
t.left(angle * 2)
|
||||
tree(branchLen-getLen(t),t)
|
||||
t.right(angle)
|
||||
t.backward(branchLen)
|
||||
t.color("brown")
|
||||
|
||||
|
||||
def main():
|
||||
t = turtle.Turtle()
|
||||
myWin = turtle.Screen()
|
||||
t.left(90)
|
||||
t.up()
|
||||
t.backward(100)
|
||||
t.down()
|
||||
t.color("brown")
|
||||
t.speed(10)
|
||||
t.pensize(5)
|
||||
tree(75,t)
|
||||
myWin.exitonclick()
|
||||
|
||||
main()
|
||||
|
||||
|
||||
Loading…
Reference in a new issue