import os
import random
from drawMethods import drawCircle, drawSquare
from palettes import randomNamedPalette
from util import getTurtleAndScreen
# Divided Colored Circles
# CAC, 2024
cellSize=150
numCols=8
numRows=6
width=cellSize*numCols
height = cellSize*numRows
name,palette = randomNamedPalette()
sides = random.randint(3,9)
filename = os.path.basename(__file__)[0:-3]
turtle, screen = getTurtleAndScreen("Divided Circles Rotated ("+name+") "+str(sides)+" sides",width,height,filename,moveWorld=True)
wedgeAngle=360/sides
percent = .75
radius = percent * cellSize / 2
for row in range (0,numRows):
for col in range(0,numCols):
# Draw a square in the cell
x = col * cellSize
y = row * cellSize
bgcolor = random.choice(palette)
turtle.color(bgcolor)
drawSquare(turtle,x,y,cellSize)
# Draw the divided circle in the cell
x += cellSize / 2
y += cellSize / 2
startAngle=random.randint(0,round(wedgeAngle))
for i in range(0,sides):
# Keep trying random colors until you get something other
# than bgcolor so it doesn't blend with the background
color = random.choice(palette)
while(color==bgcolor):
color = random.choice(palette)
turtle.color(color)
# Draw the wedge
drawCircle(turtle, x, y, radius,start=startAngle+i*wedgeAngle,extent=wedgeAngle)
screen.mainloop()