Question

1. Use Turtle Graphics to create a tic tac toe grid in Python. Write a Python...

1. Use Turtle Graphics to create a tic tac toe grid in Python.

Write a Python program that prints a tic tac toe grid. Use Turtle Graphics to create the

graphic.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE

===============

import turtle

drawer = turtle.Turtle()

# size of board

boardSize = 300

def drawBoard():

drawer.penup()

drawer.goto(-boardSize/2, -boardSize/2)

# draws box

for i in range(4):

drawer.setheading(i*90)

drawer.pendown()

drawer.forward(boardSize)

# draws grid

for i in range(2):

drawer.penup()

drawer.goto(-boardSize / 2, ((-1)**i)*(boardSize / 6))

drawer.setheading(0)

drawer.pendown()

drawer.forward(boardSize)

drawer.penup()

drawer.setheading(270)

drawer.goto(-((-1)**i)*(boardSize / 6),boardSize / 2)

drawer.pendown()

drawer.forward(boardSize)

def drawX(row,col):

drawer.pencolor("red")

# change is 1/3 board size

change = boardSize/3

# math for hypotenuse of right triangle divided by 3

forwardAmt = ((2*boardSize**2)**(1/2))/3

# setting x and y cord

x = col * change - boardSize/2

y = boardSize/2 - row * change


# first line

drawer.penup()

drawer.goto(x,y)

drawer.pendown()

drawer.setheading(360-45)

drawer.forward(forwardAmt)

# second line

drawer.penup()

drawer.goto(x+change,y)

drawer.pendown()

drawer.setheading(180 + 45)

drawer.forward(forwardAmt)



def drawO(row,col):

drawer.pencolor("blue")

# change is 1/3 board size

change = boardSize / 3

# set x and y cord

x = col * change - boardSize / 2

y = boardSize / 3 - row * change

# moves to x and y cord and draws circle

drawer.setheading(270)

drawer.penup()

drawer.goto(x,y)

drawer.pendown()

drawer.circle(boardSize/6)


drawBoard()

# change is 1/3 board size change - boardSize/3 # math for hypotenuse of right triangle divided by 3 forwardAmt((2*boardSize*

OUTPUT

> Is there any chance you know how to make a graph paper using turtle graphic when the lines have a length and of 300?

Flor García Mon, Feb 28, 2022 8:00 PM

Add a comment
Know the answer?
Add Answer to:
1. Use Turtle Graphics to create a tic tac toe grid in Python. Write a Python...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT