Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import turtle
- import math
- import random
- import time
- Tree = turtle.Turtle()
- def tree(x, y, a, old_width):
- width = 0
- if old_width < 8:
- return
- x1 = round(x + old_width * math.cos(a))
- y1 = round(y + old_width * math.sin(a))
- if old_width > 100:
- width = 100
- else:
- width = old_width
- if width < 40: # если это корень, а не ствол
- if random.random() > 0.5:
- Tree.color("yellow")
- else:
- Tree.color("green")
- for i in range(3):
- Tree.setpos(x+i, y)
- Tree.goto(x1, y1)
- else:
- Tree.color("brown")
- for i in range(round(width/6)):
- Tree.up()
- Tree.setpos(x+i-round(width/12), y)
- Tree.down()
- Tree.goto(x1, y1)
- for i in range(9-random.randint(1, 9)):
- s = random.randint(1, old_width - round(old_width / 6)) + round(old_width / 6)
- a1 = a + 1.6 * (0.5-random.random())
- x1 = round(x+s*math.cos(a))
- y1 = round(y+s*math.sin(a))
- tree(x1, y1, a1, width-5-random.randint(0, 30))
- def main():
- tree(0, 0, math.pi/2, 200)
- time.sleep(50)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement