Advertisement
MystMe

Untitled

Jul 7th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. import turtle
  2. import math
  3. import random
  4. import time
  5.  
  6.  
  7. Tree = turtle.Turtle()
  8.  
  9.  
  10. def tree(x, y, a, old_width):
  11.     width = 0
  12.     if old_width < 8:
  13.         return
  14.     x1 = round(x + old_width * math.cos(a))
  15.     y1 = round(y + old_width * math.sin(a))
  16.     if old_width > 100:
  17.         width = 100
  18.     else:
  19.         width = old_width
  20.     if width < 40:  # если это корень, а не ствол
  21.         if random.random() > 0.5:
  22.             Tree.color("yellow")
  23.         else:
  24.             Tree.color("green")
  25.         for i in range(3):
  26.             Tree.setpos(x+i, y)
  27.             Tree.goto(x1, y1)
  28.     else:
  29.         Tree.color("brown")
  30.         for i in range(round(width/6)):
  31.             Tree.up()
  32.             Tree.setpos(x+i-round(width/12), y)
  33.             Tree.down()
  34.             Tree.goto(x1, y1)
  35.     for i in range(9-random.randint(1, 9)):
  36.         s = random.randint(1, old_width - round(old_width / 6)) + round(old_width / 6)
  37.         a1 = a + 1.6 * (0.5-random.random())
  38.         x1 = round(x+s*math.cos(a))
  39.         y1 = round(y+s*math.sin(a))
  40.         tree(x1, y1, a1, width-5-random.randint(0, 30))
  41.  
  42.  
  43. def main():
  44.     tree(0, 0, math.pi/2, 200)
  45.     time.sleep(50)
  46.  
  47.  
  48. if __name__ == "__main__":
  49.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement