-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10-Reflection.py
86 lines (59 loc) · 1.48 KB
/
10-Reflection.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
# Reflection
from graphics import*
import numpy as np
def reflect(pointsA, axis):
pointsB = []
if axis=='x':
for x,y in pointsA:
xf = x
yf = -y
pointsB.append((xf,yf))
elif axis=='y':
for x,y in pointsA:
xf = -x
yf = y
pointsB.append((xf,yf))
elif axis=='o':
for x,y in pointsA:
xf = -x
yf = -y
pointsB.append((xf,yf))
return pointsB
def plot(pointsA, pointsB, isClosed):
win = GraphWin("Reflection", 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("green")
l.setWidth(5)
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("blue")
l.setWidth(3)
l.draw(win)
win.getMouse()
def main():
pointsA = [(50,50), (100,100), (150,100), (100,50)]
isClosed = True
pointsB = reflect(pointsA, 'x')
print(pointsB)
plot(pointsA.copy(), pointsB, isClosed)
pointsB = reflect(pointsA, 'y')
print(pointsB)
plot(pointsA.copy(), pointsB, isClosed)
pointsB = reflect(pointsA, 'o')
print(pointsB)
plot(pointsA.copy(), pointsB, isClosed)
main()