281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 A B C #### 0005, Code Box 3.4 # fractal_tree.py import turtle t=turtle # set variables detail=12 #decrease for more branches length=80 # increase for larger tree thickness=20 # vary to see effect angle=20 # vary to see effect t.speed(0) # 1=slow, 10=fast, 0=fastest def draw_tree(branch_thickness, branch_length): if branch_length > 5: if branch_length < 20: t.color("green") else : t.color("brown") t.pensize(branch_thickness) t.forward(branch_length) t.right(angle) draw_tree(branch_thickness/1.5, branch_length-detail) t.left(2*angle) draw_tree(branch_thickness/1.5, branch_length-detail) t.right(angle) t.back(branch_length) t.color("brown") # move turtle down the screen and turn to face up t.left(90) t.penup() t.back(100) t.pendown() # set pen color and call the main function t.color("brown") draw_tree(thickness, length) t.done() 7