Turtle
047_Rough_Circles2.py
import random
import os
from palettes import randomPalette
from util import getTurtleAndScreen
# Rough Circles Version 2
# CAC, 4/26/2023
def roughCircle(turtle,x,y,radius):
turtle.penup()
margin = radius*.02
points = []
for i in range(0,359):
turtle.goto(x,y)
turtle.setheading(i)
turtle.forward(radius+random.randrange(-margin,margin))
points.append(turtle.pos())
turtle.goto(points[0])
turtle.pendown()
turtle.begin_fill()
for p in points:
turtle.goto(p)
turtle.end_fill()
def Draw():
title = "Rough Circles 2"
width = 800
height = 600
cellSize = 200
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
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)
roughCircle(turtle,x,y,radius)
turtle.penup()
turtle.goto(0,0)
screen.mainloop()
# ----------------------------------------------------------------
if __name__ == '__main__':
Draw()
|