Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f41e704

Browse files
authored
Merge pull request #38 from sumukhmg/branch1
added y fractal tree
2 parents c9064de + da15e1f commit f41e704

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

Turtleprojects/yfractaltree.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from turtle import *
2+
3+
4+
speed('fastest')
5+
6+
# turning the turtle to face upwards
7+
rt(-90)
8+
9+
# the acute angle between
10+
# the base and branch of the Y
11+
angle = 30
12+
13+
# function to plot a Y
14+
def y(sz, level):
15+
16+
if level > 0:
17+
colormode(255)
18+
19+
# splitting the rgb range for green
20+
# into equal intervals for each level
21+
# setting the colour according
22+
# to the current level
23+
pencolor(0, 255//level, 0)
24+
25+
# drawing the base
26+
fd(sz)
27+
28+
rt(angle)
29+
30+
# recursive call for
31+
# the right subtree
32+
y(0.8 * sz, level-1)
33+
34+
pencolor(0, 255//level, 0)
35+
36+
lt( 2 * angle )
37+
38+
# recursive call for
39+
# the left subtree
40+
y(0.8 * sz, level-1)
41+
42+
pencolor(0, 255//level, 0)
43+
44+
rt(angle)
45+
fd(-sz)
46+
47+
48+
# tree of size 80 and level 7
49+
y(80, 7)

0 commit comments

Comments
 (0)