-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathexercise_17.py
48 lines (41 loc) · 1.35 KB
/
exercise_17.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
from zelle_modules.regression import Regression
from graphics import *
def graphWin(Title):
#Create a graphics window with <done> button in bottom left corner
win = GraphWin(Title, 400, 400)
win.setCoords(-10, -10, 10, 10)
#Tell user to select multiple locations on the screen to designate points
message = Text(Point(-5, 8), "Click to delineate points on the graph.")
message.draw(win)
axisX = Line(Point(-10,0), Point(10,0))
axisX.draw(win)
axisY = Line(Point(0,10), Point(0,-10))
axisY.draw(win)
r = Rectangle(Point(-9, -9), Point(-7,-8))
r.draw(win)
rCenter = r.getCenter()
stopMouse = Text(rCenter, "Done")
stopMouse.draw(win)
return win
def main():
win = graphWin("Regression Line")
allPoints = []
bestfit = Regression(win, allPoints, -10, 10)
click = win.getMouse()
click.draw(win)
p1 = win.getMouse()
p1.draw(win)
bestfit.addPoint(p1)
bestfit.addPoint(click)
bestfit.drawRegressionLine(win)
while True:
click = win.getMouse()
if ((-9 <= click.getX() <= -7) and (-9 <= click.getY() <= -8)):
break
else:
#Store user points in an appended list
bestfit.addPoint(click)
click.draw(win)
bestfit.unDraw()
bestfit.drawRegressionLine(win)
if __name__ == '__main__': main()