-
Notifications
You must be signed in to change notification settings - Fork 0
/
chessboard
78 lines (73 loc) · 2.06 KB
/
chessboard
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import turtle
def drawRectangle(width, height):
rectangleWidth = width / 8
rectangleHeight = height / 8
turtle.showturtle()
turtle.begin_fill()
turtle.fd(rectangleWidth)
turtle.left(90)
turtle.fd(rectangleHeight)
turtle.left(90)
turtle.fd(rectangleWidth)
turtle.left(90)
turtle.fd(rectangleHeight)
turtle.left(90)
turtle.end_fill()
def drawAllRectangles(width, height):
count = 0
while count <= 31:
drawRectangle(width, height)
count += 1
turtle.showturtle()
turtle.fd(width / 4)
if count == 4:
turtle.left(90)
turtle.fd(height / 8)
turtle.right(90)
turtle.backward(width - (width / 8))
if count == 8:
turtle.left(90)
turtle.fd(height / 8)
turtle.right(90)
turtle.backward(width + (width / 8))
if count == 12:
turtle.left(90)
turtle.fd(height / 8)
turtle.right(90)
turtle.backward(width - (width / 8))
if count == 16:
turtle.left(90)
turtle.fd(height / 8)
turtle.right(90)
turtle.backward(width + (width / 8))
if count == 20:
turtle.left(90)
turtle.fd(height / 8)
turtle.right(90)
turtle.backward(width - (width / 8))
if count == 24:
turtle.left(90)
turtle.fd(height / 8)
turtle.right(90)
turtle.backward(width + (width / 8))
if count == 28:
turtle.left(90)
turtle.fd(height / 8)
turtle.right(90)
turtle.backward(width - (width / 8))
def drawChessboard(startX, startY, width=250, height=250):
turtle.showturtle
turtle.pu()
turtle.goto(startX, startY)
turtle.pd()
turtle.fd(width)
turtle.left(90)
turtle.fd(height)
turtle.left(90)
turtle.fd(width)
turtle.left(90)
turtle.fd(height)
turtle.left(90)
drawAllRectangles(width, height)
turtle.hideturtle()
turtle.done()