import os
import random
from util import getTurtleAndScreen
# Random Colored Squares
# CAC, 2024
# For this one I determine the size of the screen by first realizing I want
# to break it up into an 8x8 grid of a given size square cell.
cellSize=100
numCols=8
numRows=8
# Compute the overall width and height based on cellSize, numCols, and numRows
width=cellSize*numCols
height = cellSize*numRows
colors = ["red","yellow",(0,255,0),"#FFFFFF",'#0000BB',(127,127,127),"turquoise","#E8205A"]
filename = os.path.basename(__file__)[0:-3]
turtle, screen = getTurtleAndScreen("Random Colored Squares",width,height,filename,moveWorld=True)
screen.bgcolor("gray")
for row in range (0,numRows):
for col in range(0,numCols):
# Move to the lower left corner of the cell.
turtle.penup()
turtle.goto(col*cellSize,row*cellSize)
turtle.pendown()
# Getting random color
# Technique 1: Use random choice to get
# a random color from the array
#color = random.choice(colors)
#turtle.color(color)
# Technique 2: Get a random index and
# use it to index into the array.
colorNumber = random.randint(0,7)
turtle.color(colors[colorNumber])
# Draw a square, filled in.
turtle.begin_fill()
turtle.setheading(0)
for i in range(0,4):
turtle.forward(cellSize)
turtle.left(90)
turtle.end_fill()
screen.mainloop()