Turtle
038_Gradients.py
import random
import os
from drawMethods import drawGradientCircle
from palettes import randomPalette
from util import getTurtleAndScreen
# Gradients
# CAC, 4/17/2023
def Draw():
width = 800
height = 600
cellSize = 25*random.randint(1,10)
radius = cellSize//2
cols = width//cellSize
rows = height//cellSize
number = random.randint(3,9)
title = "Gradient Circles "+str(number)+" Charles Cusack, 2023"
filename = os.path.basename(__file__)[0:-3]
turtle, screen = getTurtleAndScreen(title, width, height, filename, moveWorld=True)
colors = randomPalette()
bg = random.choice(colors)
if random.randint(0,1):
colors.remove(bg)
screen.bgcolor(bg)
for row in range(rows):
for col in range(cols):
x = cellSize*col+radius
y = cellSize*row+radius
color1=random.choice(colors)
color2=random.choice(colors)
while (color2 == color1):
color2 = random.choice(colors)
drawGradientCircle(turtle, x, y, radius, number, color1, color2)
turtle.penup()
screen.mainloop()
# ----------------------------------------------------------------
if __name__ == '__main__':
Draw()
|