Advertisement
here2share

# t_blossom_tree.py

May 29th, 2019
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. # t_blossom_tree.py
  2.  
  3. # might take about 30 seconds to render
  4.  
  5. from turtle import *
  6. from random import *
  7. from math import *
  8.  
  9. def tree(n, l):
  10.     pd()
  11.     t = cos(radians(heading() + 45)) / 8 + 0.25
  12.     pencolor(t, t, t)
  13.     pensize(n / 3)
  14.     forward(l)
  15.  
  16.  
  17.     if n > 0:
  18.         b = random() * 15 + 10
  19.         c = random() * 15 + 10
  20.         d = l * (random() * 0.25 + 0.7)
  21.         right(b)
  22.         tree(n - 1, d)
  23.         left(b + c)
  24.         tree(n - 1, d)
  25.         right(c)
  26.     else:
  27.         right(90)
  28.         n = cos(radians(heading() - 45)) / 4 + 0.5
  29.         pencolor(n, n*0.8, n*0.8)
  30.         circle(3)
  31.         left(90)
  32.  
  33.         if(random() > 0.7):
  34.             pu()
  35.             t = heading()
  36.             an = -40 + random()*40
  37.             setheading(an)
  38.             dis = int(800*random()*0.5 + 400*random()*0.3 + 200*random()*0.2)
  39.             forward(dis)
  40.             setheading(t)
  41.  
  42.  
  43.             pd()
  44.             right(90)
  45.             n = cos(radians(heading() - 45)) / 4 + 0.5
  46.             pencolor(n*0.5+0.5, 0.4+n*0.4, 0.4+n*0.4)
  47.             circle(2)
  48.             left(90)
  49.             pu()
  50.  
  51.             t = heading()
  52.             setheading(an)
  53.             backward(dis)
  54.             setheading(t)
  55.  
  56.     pu()
  57.     backward(l)
  58.  
  59. bgcolor(0.5, 0.5, 0.5)
  60. ht()
  61. speed(0)
  62. tracer(0, 0)
  63. pu()
  64. backward(100)
  65. left(90)
  66. pu()
  67. backward(300)
  68. tree(12, 100)
  69. done()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement