-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path07-Translation.py
62 lines (41 loc) · 1.07 KB
/
07-Translation.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
# Translation
from graphics import*
def translate(pointsA, tx, ty):
pointsB = []
for x,y in pointsA:
pointsB.append((x+tx,y+ty))
return pointsB
def plot(pointsA, pointsB, isClosed):
win = GraphWin("Translation", 500, 500)
win.setCoords(-250,-250,250,250)
l = Line(Point(0,-250), Point(0,250))
l.draw(win)
l = Line(Point(-250,0), Point(250,0))
l.draw(win)
if isClosed:
pointsA.append(pointsA[0])
pointsB.append(pointsB[0])
for i in range(len(pointsA)-1):
(x1,y1) = pointsA[i]
(x2,y2) = pointsA[i+1]
l = Line(Point(x1,y1), Point(x2,y2))
l.setOutline("blue")
l.setWidth(3)
l.draw(win)
for i in range(len(pointsB)-1):
(x1,y1) = pointsB[i]
(x2,y2) = pointsB[i+1]
l = Line(Point(x1,y1), Point(x2,y2))
l.setOutline("green")
l.setWidth(3)
l.draw(win)
win.getMouse()
def main():
pointsA = [(50,50), (100,100), (150,100), (100,50)]
isClosed = True
tx = 100
ty = 30
pointsB = translate(pointsA, tx, ty)
print(pointsB)
plot(pointsA, pointsB, isClosed)
main()