|
|
Summer24
015_Concentric_Divided_Circles.py
import os
import random
from util import getTurtleAndScreen
def drawSquareLL(turtle,x,y,cellSize):
turtle.penup()
turtle.goto(x,y)
turtle.setheading(0)
turtle.pendown()
turtle.begin_fill()
for i in range(4):
turtle.forward(cellSize)
turtle.left(90)
turtle.end_fill()
def drawCircle(turtle,x,y,radius,extent=360,start=0):
turtle.penup()
turtle.goto(x,y)
turtle.pendown()
turtle.begin_fill()
turtle.setheading(start)
turtle.forward(radius)
turtle.left(90)
turtle.circle(radius,extent=extent)
turtle.goto(x,y)
turtle.end_fill()
def drawDividedCircle(turtle,x,y,radius,howMany,palette):
wedgeDegree=360/howMany
start = random.randint(0,359)
for i in range(howMany):
turtle.color(random.choice(palette))
drawCircle(turtle,x,y,radius,extent=wedgeDegree,start=start+i*wedgeDegree)
def drawConcentricDividedCircles(turtle,x,y,cellSize,howMany,palette):
for i in range(howMany):
radius = (howMany-i)*cellSize/((howMany+1)*2)
thisMany=random.randint(2,8)
drawDividedCircle(turtle,x,y,radius,thisMany,palette)
aspectRatio = 1.5
height = 800
width = height*aspectRatio
numRows = 4
numCols = round(numRows*aspectRatio)
cellSize = height/numRows
# cellSize = width/numCols
filename = os.path.basename(__file__)[0:-3]
turtle, screen = getTurtleAndScreen("Concentric Divided Cirlces",width,height,filename,moveWorld=True)
palette = ['#F46A1F', '#002244', '#91420E', '#F0AB00', '#F7E654', '#BED600', '#00685B', '#5482AB', '#00B0CA']
for row in range(0,numRows):
for col in range(0,numCols):
turtle.color(random.choice(palette))
x=cellSize*col
y=cellSize*row
drawSquareLL(turtle,x,y,cellSize)
# color background
x+=cellSize/2 # x=x+cellSize/2
y+=cellSize/2
howMany = random.randint(3,7)
drawConcentricDividedCircles(turtle,x,y,cellSize,howMany,palette)
# draw concentric divided circles
screen.mainloop()
|