image.png

    1. import turtle as T
    2. import random
    3. import time
    4. # Draw the truck of the cherry tree(60,t)
    5. def Tree(branch, t):
    6. time.sleep(0.0005)
    7. if branch > 3:
    8. if 8 <= branch <= 12:
    9. if random.randint(0, 2) == 0:
    10. t.color('snow') # White
    11. else:
    12. t.color('lightcoral') # Pale coral
    13. t.pensize(branch / 3)
    14. elif branch < 8:
    15. if random.randint(0, 1) == 0:
    16. t.color('snow')
    17. else:
    18. t.color('lightcoral') # Pale coral
    19. t.pensize(branch / 2)
    20. else:
    21. t.color('sienna') # Sienna
    22. t.pensize(branch / 10) # 6
    23. t.forward(branch)
    24. a = 1.5 * random.random()
    25. t.right(20 * a)
    26. b = 1.5 * random.random()
    27. Tree(branch - 10 * b, t)
    28. t.left(40 * a)
    29. Tree(branch - 10 * b, t)
    30. t.right(20 * a)
    31. t.up()
    32. t.backward(branch)
    33. t.down()
    34. # Draw the fallen patals
    35. def Petal(m, t):
    36. for i in range(m):
    37. a = 200 - 400 * random.random()
    38. b = 10 - 20 * random.random()
    39. t.up()
    40. t.forward(b)
    41. t.left(90)
    42. t.forward(a)
    43. t.down()
    44. t.color('lightcoral') # Pale coral
    45. t.circle(1)
    46. t.up()
    47. t.backward(a)
    48. t.right(90)
    49. t.backward(b)
    50. # Drawing area
    51. t = T.Turtle()
    52. # Canvas size
    53. w = T.Screen()
    54. t.hideturtle() # Hide the pen
    55. t.getscreen().tracer(5, 0)
    56. w.screensize(bg='wheat') # Wheat
    57. t.left(90)
    58. t.up()
    59. t.backward(150)
    60. t.down()
    61. t.color('sienna')
    62. # Draw the trunk of the cherry tree
    63. Tree(60, t)
    64. # Draw the fallen petals
    65. Petal(200, t)
    66. w.exitonclick()