Advertisement
pacho_the_python

l-system plant

Apr 22nd, 2024
542
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. def plant(length, decrease, angle, constant):
  2.     if length > 10:
  3.         tr.width(length / 10)
  4.         tr.forward(length)
  5.         new_length = length * decrease
  6.         if constant > 0:
  7.             new_length *= random.uniform(0.8, 1.1)
  8.         angle_l = angle + random.gauss(0, constant)
  9.         angle_r = angle + random.gauss(0, constant)
  10.  
  11.         tr.left(angle_l)
  12.         plant(new_length, decrease, angle, constant)
  13.         tr.right(angle_l)
  14.  
  15.         tr.right(angle_r)
  16.         plant(new_length, decrease, angle, constant)
  17.         tr.left(angle_r)
  18.  
  19.         tr.backward(length)
  20.  
  21.  
  22. tr.penup()
  23. tr.goto(0, -400)
  24. tr.pendown()
  25. tr.left(90)
  26. tr.tracer(30, 0)
  27. plant(150, 0.8, 20, 5)
  28. tr.tracer(True)
  29. tr.exitonclick()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement