Python Program Colored Tree Using Turtle
- Turtle is a Python feature like a drawing board.
- Turtle is a special feathers of Python.
- You can use functions like turtle.forword (....) and turtle.left(....) which can move the turtle around the board.
- These are Python Turtle project, you are going to draw a Colored Tree.
Installation
pip install pythonturtle
or
sudo pip install pythonturtle
The First step is to import libraries
import turtle
or
from turtle import *
Turtle_tree.py
import turtle
import colorsys
def draw_stick(x, y, length, pensize, color, angle):
turtle.up()
turtle.goto(x, y)
turtle.seth(angle)
turtle.pensize(pensize)
turtle.down()
turtle.color(color)
turtle.fd(length)
def draw_tree(x, y, length, pensize, hue, angle, fat_angle, n):
if n == 0:
return
(r, g, b) = colorsys.hsv_to_rgb(hue, 1, 1)
draw_stick(x, y, length, pensize, (r, g, b), angle)
tx = turtle.xcor()
ty = turtle.ycor()
draw_tree(tx, ty, length * 0.7, pensize * 0.7, hue - 1 / 13,
angle + fat_angle, fat_angle, n - 1)
draw_tree(tx, ty, length * 0.7, pensize * 0.7, hue - 1 / 13,
angle - fat_angle, fat_angle, n - 1)
turtle.setup(800, 800)
turtle.title("My Rainbow Colored Tree By:- Codes With Sunny")
turtle.speed(5)
turtle.hideturtle()
turtle.tracer(5)
turtle.bgcolor('black')
draw_tree(0, -300, 200, 10, 12 / 13, 90, 25, 12)
turtle.update()
0 Comments
Please Do Not Comments Any Span Or Span link..