Y Fractal tree in Python using Turtle Last Updated : 02 Jul, 2020 Summarize Suggest changes Share Like Article Like Report A fractal is a never-ending pattern. Fractals are infinitely complex patterns that are self-similar across different scales. They are created by repeating a simple process over and over in an ongoing feedback loop. Driven by recursion, fractals are images of dynamic systems – the pictures of Chaos. In this article, we will draw a colorful Y fractal tree using a recursive technique in Python. Examples: Output for depth level: (a) 14 (b) 12 Modules required turtle: turtle library enables users to draw picture or shapes using commands, providing them with a virtual canvas. turtle comes with Python's Standard Library. It needs a version of Python with Tk support, as it uses tkinter for the graphics. Functions used: fd(x) : draw the cursor forward by x pixels. rt(x), lt(x) : rotates the facing direction of the cursor by x degrees to the right and left respectively. colormode(): to change the colour mode to rgb. pencolor(r, g, b): to set the colour of the turtle pen. speed(): to set the speed of the turtle. Approach : We start by drawing a single 'Y' shape for the base(level 1) tree. Then both the branches of the 'Y' serve as the base of other two 'Y's(level 2). This process is repeated recursively and size of the Y decreases as level increases. Colouring of the tree is done level wise: darkest in the base level to lightest in the topmost. In the implementation below, we will draw a tree of size 80 and level 7. Python3 1== from turtle import * speed('fastest') # turning the turtle to face upwards rt(-90) # the acute angle between # the base and branch of the Y angle = 30 # function to plot a Y def y(sz, level): if level > 0: colormode(255) # splitting the rgb range for green # into equal intervals for each level # setting the colour according # to the current level pencolor(0, 255//level, 0) # drawing the base fd(sz) rt(angle) # recursive call for # the right subtree y(0.8 * sz, level-1) pencolor(0, 255//level, 0) lt( 2 * angle ) # recursive call for # the left subtree y(0.8 * sz, level-1) pencolor(0, 255//level, 0) rt(angle) fd(-sz) # tree of size 80 and level 7 y(80, 7) Output : Advertise with us Next Article Draw Circle in Python using Turtle C cosine1509 Follow Similar Reads Draw tree using Turtle module in Python Prerequisite: Turtle module, Drawing Triangle, Drawing Rectangle There are many modules in python which depicts graphical illustrations, one of them is turtle, it is an in-built module in Python, which lets the user control a pen(turtle) to draw on screen(drawing board). It is mostly used to illustr 2 min read Fractal Trees in Python Implementation of Fractal Binary Trees in python. Introduction A fractal tree is known as a tree which can be created by recursively symmetrical branching. The trunk of length 1 splits into two branches of length r, each making an angle q with the direction of the trunk. Both of these branches divid 3 min read Draw Circle in Python using Turtle Turtle graphics is an engaging way to learn Python programming by visualizing geometric shapes. The turtle module lets you control a turtle to draw lines and shapes on the screen, making it an ideal tool for beginners. Below, we'll explore how to draw circles and create more complex patterns like ta 2 min read Fractal using Spirograph in Python Introduction Spirograph toy that is used to produce complex patterns using plastic cogs and colored pens. A fractal is a curve, that is developed using a recurring pattern that repeats itself infinitely on a low scale. Fractals are used for modeling structures (such as snowflakes) or for describing 6 min read Draw Ellipse Using Turtle in Python Prerequisite: Turtle Programming Basics Turtle is an inbuilt module in Python. It provides drawing using a screen (cardboard) and turtle (pen). To draw something on the screen, we need to move the turtle (pen). To move turtle, there are some functions i.e forward(), backward(), etc. Approach: The fo 2 min read turtle.turtlesize() function in Python The turtle module provides turtle graphics primitives, in both object-oriented and procedure-oriented ways. Because it uses Tkinter for the underlying graphics, it needs a version of Python installed with Tk support. turtle.turtlesize() This function is used to return or set the pen's attributes x o 2 min read Article Tags : Python Python-turtle Practice Tags : python Like