Programming Resources
For Fun and Learning
Charles Cusack
Computer Science
Hope College
main


Python


C++
JAVA
PHP
SQL
Assignments

Turtle


009_ArcsPalettes.py

import random
import os
from drawMethods import drawCircle
from palettes import randomNamedPalette, getPalette
from util import getTurtleAndScreen

# Arcs
# Added using colors from a palette.
# CAC, 3/13/2023

def Draw():
    title = "Goofy looking Arcs that I am not sure I like"
    width = 800
    height = 600
    cellSize = 50
    numCols = width // cellSize
    numRows = height // cellSize

    # To get the colors of a specific palette whose name you know.
    #name = 'Tol Dark (6)'
    #colors = getPalette(name)

    name,colors = randomNamedPalette()

    bg = random.choice(colors)
    if random.randint(0,1)==0:
        colors.remove(bg)


    print(colors)
    colors = getPalette(name)
    print(colors)

    title +=" ("+name+")"

    filename = os.path.basename(__file__)[0:-3]
    turtle, screen = getTurtleAndScreen(title,width,height,filename,moveWorld=True)

    screen.bgcolor(bg)

    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)

            lineWidth = 2*random.randint(1,10)
            extent = random.randint(90,360)
            start = random.randint(0,359)
            drawCircle(turtle,x,y,radius,lineWidth,extent,start)
            #drawCircle(turtle,x,y,radius)

    turtle.penup()
    turtle.goto(0,0)

    screen.mainloop()
# ----------------------------------------------------------------
if __name__ == '__main__':
   Draw()