Skip to content

Commit 776639e

Browse files
Merge pull request #108 from krishna-verma/two-chess-board
Add files via upload
2 parents db71a1c + 5681518 commit 776639e

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

TwoChessBoard.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import turtle
2+
3+
def main():
4+
drawChessboard(-260, -20, -120, 120) # Draw first chess board
5+
drawChessboard(20, 260, -120, 120) # Draw second chess board
6+
7+
turtle.hideturtle()
8+
turtle.done()
9+
10+
# Draw one chess board
11+
def drawChessboard(startx, endx, starty, endy):
12+
# Draw chess board borders
13+
turtle.pensize(3) # Set pen thickness to 3 pixels
14+
turtle.penup() # Pull the pen up
15+
turtle.goto(startx, starty)
16+
turtle.pendown() # Pull the pen down
17+
turtle.color("red")
18+
19+
for i in range(4):
20+
turtle.forward(240) # Draw a line
21+
turtle.left(90) # Turn left 90 degrees
22+
23+
# Draw chess board inside
24+
drawMultipleRectangle(startx, endx, starty, endy)
25+
drawMultipleRectangle(startx + 30, endx, starty + 30, endy)
26+
27+
# Draw multiple rectangles
28+
def drawMultipleRectangle(startx, endx, starty, endy):
29+
turtle.color("black")
30+
for j in range(starty, endy, 60):
31+
for i in range(startx, endx, 60):
32+
fillRectangle(i, j)
33+
34+
# Draw a small rectangle
35+
def fillRectangle(i, j):
36+
turtle.penup()
37+
turtle.goto(i, j)
38+
turtle.pendown()
39+
turtle.begin_fill()
40+
for k in range(4):
41+
turtle.forward(30) # Draw a line
42+
turtle.left(90) # Turn left 90 degrees
43+
turtle.end_fill()
44+
45+
main()

0 commit comments

Comments
 (0)