Python Turtle is a graphics library that simply allows you to draw and create shapes on the screen using a moving turtle. You can nudge the turtle around by giving commands like "move forward 50 units" or "turn left 90 degrees."

Python Turtle is a fantastic tool for teaching the fundamentals of programming, especially to young students, and it is a part of the standard Python distribution. It's simple to get started with, and you can see the results right away on the screen, making it an interesting and enjoyable way to learn how to code.

Python Turtle offers a straightforward and understandable interface for creating shapes and lines, colouring in spaces, and managing events like mouse clicks and key presses.. You can design a wide range of graphics with Python Turtle, from straightforward shapes to intricate fractals.



Source Code :


import turtle

screen = turtle.Screen()
screen.setup(800,800)
screen.setworldcoordinates(-8,-8,8,8)
screen.tracer(0,0)
screen.title('Bulge Illusion - PythonTurtle.Academy')
turtle.hideturtle()
turtle.speed(0)

color1 = 'light sky blue'
color2 = 'firebrick'
screen.bgcolor(color2)

def draw_square(x,y,size,c):
    turtle.up()
    turtle.goto(x-size/2,y-size/2)
    turtle.seth(0)
    turtle.color(c)
    turtle.begin_fill()
    for _ in range(4):
        turtle.fd(size)
        turtle.left(90)
    turtle.end_fill()
   
def draw_board():
    for x in range(-7,8,2):
        for y in range(-7,8,2):
            draw_square(x,y,1,color1)
    for x in range(-6,8,2):
        for y in range(-6,8,2):
            draw_square(x,y,1,color1)
           

def draw_diag(x,y):
    c = color2 if (x+y)%2 == 0 else color1
    if x*y > 0:
        draw_square(x-0.3,y+0.3,0.3,c)
        draw_square(x+0.3,y-0.3,0.3,c)
    elif x*y < 0:
        draw_square(x+0.3,y+0.3,0.3,c)
        draw_square(x-0.3,y-0.3,0.3,c)

def draw_straight(x,y):
    c = color2 if (x+y)%2 == 0 else color1
    if y>0:
        draw_square(x-0.3,y-0.3,0.3,c)
        draw_square(x+0.3,y-0.3,0.3,c)
    elif y<0:
        draw_square(x-0.3,y+0.3,0.3,c)
        draw_square(x+0.3,y+0.3,0.3,c)
    elif x>0:
        draw_square(x-0.3,y-0.3,0.3,c)
        draw_square(x-0.3,y+0.3,0.3,c)
    elif x<0:
        draw_square(x+0.3,y-0.3,0.3,c)
        draw_square(x+0.3,y+0.3,0.3,c)
       
def draw_bulge():
    for x in range(-6,7):
        for y in range(-6,7):
            if abs(x)+abs(y)<=7:
                draw_diag(x,y)
                if x==0 or y==0: draw_straight(x,y)
    x,y = -5,-3
    for i in range(3):
        draw_diag(x,y)
        draw_diag(-x,-y)
        draw_diag(x,-y)
        draw_diag(-x,y)
        x += 1
        y -= 1
draw_board()
draw_bulge()
screen.update()

turtle.done()