Creating an animated tree using Python can be a fun project

 Creating an animated tree using Python can be a fun project

source code


import turtle

def draw_tree(branch_len, t):
    if branch_len < 5:
        return

    t.forward(branch_len)
    t.right(20)
    draw_tree(branch_len - 15, t)

    t.left(40)
    draw_tree(branch_len - 15, t)

    t.right(20)
    t.backward(branch_len)

def main():
    t = turtle.Turtle()
    screen = turtle.Screen()
    screen.setup(800, 600)
    screen.bgcolor("black")
    t.speed(0)  # Set the drawing speed (0 is the fastest)

    t.left(90)
    t.up()
    t.backward(200)
    t.down()
    t.color("green")

    draw_tree(100, t)

    screen.exitonclick()

if __name__ == "__main__":
    main()

Comments

Popular posts from this blog

Trading Live Advance Chart Source code HTML CSS & JS

How to show live Cryptocurrency Price In your website Using HTML CSS, AND JavaScript

Learn Python 2024 by gaurav tripathi