You are on page 1of 2

import turtle

import random

#screen settings

screen=turtle.Screen()

screen.setup(600,500)

screen.bgcolor("black")

#pen setup

pen=turtle.Turtle()

pen.pensize(2)

pen.color("white")

pen.hideturtle()

pen.speed(0)

#function for drawing squares

def drawSquare(length,color):

pen.color(color)

for _ in range(4):

pen.forward(length)

pen.left(90)

#create a list of colors

color_list=["red","white","blue","lightblue"]

#generate random squares

for _ in range(100):

pen.penup()

x=random.randint(-300,300)
y=random.randint(-250,250)

pen.goto(x,y)

pen.pendown()

length=random.randint(50,200)

color=random.choice(color_list)

drawSquare(length,color)

You might also like