Skip to content

Instantly share code, notes, and snippets.

@spaghettiSyntax
Created December 5, 2017 15:18
Show Gist options
  • Save spaghettiSyntax/4c4446d9873896cfdfd86f9709b6fc28 to your computer and use it in GitHub Desktop.
Save spaghettiSyntax/4c4446d9873896cfdfd86f9709b6fc28 to your computer and use it in GitHub Desktop.
Tony Gaddis Python
# This program makes a checkerboard pattern using functions.
import turtle
# Width of one square.
WIDTH = 60
NUM_ROWS = 8
def main():
turtle.hideturtle()
color_flag = 1
for row in range(NUM_ROWS):
if NUM_ROWS % 2 == 0:
color_flag += 1
for col in range(NUM_ROWS):
color_flag += 1
if color_flag % 2 == 0:
my_color = 'black'
else:
my_color = 'white'
square(WIDTH * row - NUM_ROWS * WIDTH / 2, \
WIDTH * col - NUM_ROWS * WIDTH / 2, \
WIDTH, my_color)
def square(x, y, width, color):
turtle.speed(0)
turtle.penup()
turtle.goto(x, y)
turtle.fillcolor(color)
turtle.pendown()
turtle.begin_fill()
for count in range(4):
turtle.forward(width)
turtle.left(90)
turtle.end_fill()
return square
# Start Program
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment