Programming Resources
For Fun and Learning
Charles Cusack
Computer Science
Hope College
main


Python


C++
JAVA
PHP
SQL
Assignments

Turtle


013_Filled_Circles.py

import random
import os
from drawMethods import fillCircle
from palettes import randomPalette
from util import getTurtleAndScreen
# Filled Circles
# Drawing a grid of filled circles using a new method fillCircle
# that we created in drawMethods.
# CAC, 3/15/2023

def Draw():
    title = "Filled Circles"
    width = 800
    height = 600
    cellSize = 50
    numCols = width // cellSize
    numRows = height // cellSize

    filename = os.path.basename(__file__)[0:-3]
    turtle, screen = getTurtleAndScreen(title,width,height,filename,moveWorld=True)

    colors = randomPalette()
    bg = random.choice(colors)
    screen.bgcolor(bg)
    if(random.randint(0,1)==1):
        colors.remove(bg)

    lineWidth = 2*random.randint(1,10)
    turtle.pensize(lineWidth)

    for row in range (0,numRows):
        for col in range(0,numCols):
            radius = cellSize//2
            x = col*cellSize + radius
            y = row*cellSize + radius
            color=random.choice(colors)
            turtle.color(color)
            fillCircle(turtle,x,y,radius)

    turtle.penup()
    turtle.goto(0,0)

    screen.mainloop()
# ----------------------------------------------------------------
if __name__ == '__main__':
   Draw()