from turtle import * from random import randint def add_circles(number): """ Add number colored circles of radius 4 randomly through the screen """ x_range = int( window_width()/2 ) y_range = int( window_height()/2 ) for i in range(number): x = randint(-x_range, x_range) y = randint(-y_range, y_range) # set the fill color of the circles setcolor_xy(x, y) pu() goto(x,y) pd() begin_fill() circle(8) end_fill() def setcolor_xy(x, y): """ Set the fill color based on x, y coordinates """ if x < 0 and y < 0: fillcolor("blue") elif x < 0 and y > 0: fillcolor("purple") elif x > 0 and y < 0: fillcolor("red") else: fillcolor("yellow") def setcolor_random(): """ Set the fill color randomly from: blue, purple, red and yellow """ color = randint(1,4) if color == 1: fillcolor("blue") elif color == 2: fillcolor("purple") elif color == 3: fillcolor("red") else: # color == 4 fillcolor("yellow")