Advertisement
Guest User

Tree

a guest
Dec 5th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. from graphics import *
  2. import math
  3. from random import randint
  4.  
  5. winS = 700
  6.  
  7. win = GraphWin("Tree", winS, winS)
  8.  
  9. def sin(a):
  10.     return math.sin(math.radians(a))
  11. def cos(a):
  12.     return math.cos(math.radians(a))
  13.  
  14. def tree(i,a,b=60,r=270,x=winS//2,y=winS-30):
  15.  
  16.     if a <= 0 or b < 2:
  17.         return
  18.  
  19.     xx = round(cos(r) * b)
  20.     yy = round(sin(r) * b)
  21.  
  22.     s = Line(Point(x, y), Point( x + xx, y + yy))
  23.     s.draw(win)
  24.     s.setWidth(a//1.5)
  25.  
  26.     i = randint(-30,30)
  27.     tree(i, a-1, b , r + i, x + xx, y + yy)
  28.  
  29.     if i%2==0:
  30.         tree(i, a-1, b , r - i, x + xx, y + yy)
  31.  
  32. tree(10,20,16,270)
  33.  
  34. while True:
  35.     update(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement