5/1/26

Python | Turtle Tutorial | best graphics design

i wanted to make a drawing

import turtle
tu = turtle.Turtle()
tu.screen.bgcolor("black")
tu.pensize(2)
turtle.colormode(255)

turning_yellow = True
turning_green = False
turning_cyan = False
turning_blue= False
turning_pink = False
turning_red = False

r = 255
g = 0
b = 0 
tu.color((r, g, b))
tu.left(90)

tu.backward(100)
tu.speed(200)
tu.shape("turtle")

def tree(i):
    global r, g, b
    global turning_cyan, turning_red, turning_blue, turning_pink, turning_yellow, turning_green
    if turning_yellow:
        g += 1
        if g >= 255:
            g = 255
            turning_yellow = False
            turning_green = True

    if turning_green:
        r -= 1
        if r <=0:
            r=0
            turning_green = False
            turning_cyan = True

    if turning_cyan:
        b += 1
        if b <= 255:
            b = 255
            turning_cyan = False
            turning_blue= True
    
    if turning_blue:
        r = 255 
        if r <= 0:
            r += 1 
            r = 255 



    if i<10:
        return
    else:
        tu.forward(i)
        tu.color((r, g, b))
        tu.circle(2)
        tu.color((r, g, b))
        tu.left(30)
        tree(3*i/4)
        tu.right(60)
        tree(3*i/4)
        tu.left(30)
        tu.backward(i)
tree(100)
turtle.done()

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top