-
Notifications
You must be signed in to change notification settings - Fork 0
/
turtle init test.py
102 lines (75 loc) · 1.89 KB
/
turtle init test.py
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import turtle
#5x5 (boardSize x boardSize)
boardSize=5
startX=1;startY=5
endX=3;endY=3
pic="unicorn.gif"
blank ="square.gif"
#turtle formula: goto(c*sqSize+30,30);drto(c*sqSize+30,boardSize*sqSize+30)
def initTurtle():
global sqSize
turtle.setup(1000,1000,0,0)
winH=turtle.window_height()-30;winW=turtle.window_width()-30
turtle.title("Knight's Tour")
turtle.setworldcoordinates(0,1000,1000,0)
turtle.ht()
turtle.pen(pencolor="black")
turtle.pen(pensize=3)
turtle.speed(0)
if(winW<winH):
sqSize=winW/(boardSize+1)
else:
sqSize=winH/(boardSize+1)
for r in range(0,boardSize+1): #draw horizontal rows
goto(30,r*sqSize+30)
drto(boardSize*sqSize+30,r*sqSize+30)
for c in range(0,boardSize+1): #draw vertical columns
goto((c)*sqSize+30,30)
drto(c*sqSize+30,boardSize*sqSize+30)
turtle.Screen().addshape("unicorn.gif")
turtle.Screen().addshape("square.gif")
turtle.shape(pic)
def goto(x,y):
turtle.pu()
turtle.goto(x,y)
turtle.pd()
def drto(x,y):
turtle.goto(x,y)
def clearStamp():
global step
step-=1
turtle.undo()
turtle.undo()
turtle.undo()
turtle.undo()
def stampAt(c,r):
<<<<<<< HEAD
goto((c-1)*100-350,350-(boardSize-r)*100)
turtle.shape(pic)
turtle.stamp()
def clearStamp(c,r):
goto((c-1)*100-350,350-(boardSize-r)*100)
turtle.shape(blank)
turtle.stamp()
initTurtle()
stampAt(1,1)
stampAt(2,2)
stampAt(1,5)
stampAt(5,1)
stampAt(8,8)
stampAt(8,2)
clearStamp(1,1)
=======
global step
step +=1
goto(c*sqSize,(boardSize-r+1)*sqSize)
turtle.write(step, False, "center", ("Arial",16,"normal"))
# turtle.shape(pic)
# turtle.stamp()
##def clearStamp(c,r):
## global step
## step-=1
## goto((c-1)*100-350,350-(boardSize-r)*100)
### turtle.shape(blank)
## turtle.stamp()
>>>>>>> 5x5_Board