Turtle
006_Palette_Colored_Slashes.py
import random
import os
from util import getTurtleAndScreen
# Random Colorder slashes
# CAC, 2023
def drawForwardSlash(turtle,x,y,cellSize):
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
turtle.goto(x + cellSize, y + cellSize)
def drawBackwardSlash(leon, x, y, cellSize):
leon.penup()
leon.goto(x + cellSize, y)
leon.pendown()
leon.goto(x, y + cellSize)
colors= ['#c5aeb1', '#e2c1c0', '#d29380', '#ccb97e', '#6667ab', '#86a293', '#884c5e', '#9d848e']
def randomPaletteColor():
return random.choice(colors)
width=800
height = 600
cellSize=50
numCols=width//cellSize
numRows=height//cellSize
filename = os.path.basename(__file__)[0:-3]
turtle, screen = getTurtleAndScreen("Palette Slashes",width,height,filename,moveWorld=True)
bg = randomPaletteColor()
screen.bgcolor(bg)
colors.remove(bg)
turtle.pensize(2)
for row in range (0,numRows):
for col in range(0,numCols):
x = col*cellSize
y = row*cellSize
color=randomPaletteColor()
turtle.color(color)
if(random.randint(0,1)==0):
drawForwardSlash(turtle, x, y, cellSize)
else:
drawBackwardSlash(turtle,x,y,cellSize)
turtle.penup()
turtle.goto(0,0)
screen.mainloop()
|