def draw_tour(path_d, all_nodes):
	from graphics import Point, Circle, Line, GraphWin
	maxX = max([x for x, y in all_nodes])
	minX = min([x for x, y in all_nodes])
	maxY = max([y for x, y in all_nodes])
	minY = min([y for x, y in all_nodes])

	N = 750
	norm_x = N/(maxX - minX)
	norm_y = N/(maxY - minY)

	win = GraphWin("TSP", N, N)
	for n in all_nodes:
		c = Point(*norm(n, norm_x, norm_y, minX, minY))
		c = Circle(c, 3)
		c.draw(win)

	for (k, subdict) in path_d.iteritems():
		#t = Text(Point(*subdict['center']*N), k)
		#t.draw(win)
		if not subdict['hasBeenSplit']:
			p = Point(*norm(subdict['center'], norm_x, norm_y, minX, minY))

			c1i, c2i = subdict['connections']
			c1 = Point(*norm(path_d[str(c1i)]['center'], norm_x, norm_y, minX, minY))
			c2 = Point(*norm(path_d[str(c2i)]['center'], norm_x, norm_y, minX, minY))
			l1 = Line(p, c1)
			l2 = Line(p, c2)
			l1.draw(win)
			l2.draw(win)

	win.getMouse()
	win.close()
Example #2
0
def draw_tour(tour):
    from graphics import Point, Circle, Line, GraphWin
    maxX = max([x for x, y in tour])
    minX = min([x for x, y in tour])
    maxY = max([y for x, y in tour])
    minY = min([y for x, y in tour])

    N = 750
    norm_x = N / (maxX - minX)
    norm_y = N / (maxY - minY)

    win = GraphWin("TSP", N, N)
    for n in tour:
        c = Point(*norm(n, norm_x, norm_y, minX, minY))
        c = Circle(c, 2)
        c.draw(win)

    for i, _ in enumerate(tour[:-1]):
        p1 = norm(tour[i], norm_x, norm_y, minX, minY)
        p2 = norm(tour[i + 1], norm_x, norm_y, minX, minY)
        l = Line(Point(*p1), Point(*p2))
        l.draw(win)

    win.getMouse()
    win.close()
Example #3
0
def main():
	Maths.generateMathExpressions()
	print("Available operators:")
	for o in Maths.Expressions:
		print(Maths.Expressions[o].getAbbreviation())

	print("-------------------------")
	f = Function("cos(3*x)+6/4*(x+3)", False)
	print("RPN String", f.getRpnString())
	for x in range (2, 11):
		f.compute(x)

	print("-------------------------")

	f = Function("56*((6+2)/(8-x)*2^3", False)
	print("RPN String", f.getRpnString()) #should give 56 6 2 + 8 7 - / 2 3 ^ * *


	mainwindow = MainWindow("Function Drawer", 992, 512)
	fx = f.computeRange(0, 10)
	max_y = max(fx.values())
	min_y = min(fx.values())

	print(min_y, max_y)
	mainwindow.setCoords(-1, min_y, 11, max_y)
	for x in range(0, 11):
		print(fx[x])
		p = Point(x, fx[x])
		p.draw(mainwindow)

	input("Press a key to quit")
Example #4
0
def begin():
    #Ready? Text
    begText1 = Text(Point(25,20), "Ready?")
    begText1.setFace("times roman")
    begText1.draw(win)
    sleep(1.5)
    begText1.undraw()
    sleep(0.5)

    #"Here's a point" Text and Plotting first point
    begText2 = Text(Point(25,20), "Here's a point.")
    begText2.setFace("times roman")
    begText2.draw(win)
    point1 = Point(25,25)
    point1.draw(win)
    sleep(1.5)
    begText2.undraw()
    sleep(0.5)

    #moving First point
    clickAnywhere = Text(Point(25, 20),
        "Press 'l' or 'r' to move the point off the screen in either direction.")
    clickAnywhere.setFace("times roman")
    clickAnywhere.draw(win)
    #win.getMouse()
    key = win.getKey()
    clickAnywhere.undraw()
    if key == "r":
        for i in range(55):
            point1.move(.5,0)
            sleep(0.05)
    if key == "l":
        for i in range(55):
            point1.move(-.5,0)
            sleep(0.05)
    point1.undraw()

    #First Congrats Text and Transition
    greatxt = Text(Point(25,20), "Great!")
    greatxt.setFace("times roman")
    greatxt.draw(win)
    sleep(1.5)
    greatxt.undraw()
    tranText = Text(Point(25,20), "Now, click your mouse on the window to create a red circle")
    tranText.setFace("times roman")
    tranText.draw(win)
    win.getMouse()
    tranText.undraw()
    #call to next function
    drawCircle()
Example #5
0
def main():
    win = GraphWin("map", 1000, 800)
    win.setCoords(-88.357, 41.786, -88.355, 41.788)

    with open("2016-08-04_20-20-41.000.txt", "r") as log:
        lines = log.readlines()
        for n in range(0, len(lines) - 1, 3):
            line = lines[n].split(", ")
            if len(line) == 6:
                p = Point(float(line[2]), float(line[1]))
                p.setFill('red')
                Line(p, vect(p, radians(-(float(line[3]) + 270)))).draw(win)
                p.draw(win)

            else:
                Text(Point(float(lines[n+1].split(", ")[2]) + .00005, float(lines[n+1].split(", ")[1]) + .00005), line[0]).draw(win)
                print(line)
Example #6
0
def test(points,
         number_of_clusters,
         solution=None,
         max_iterations=100,
         method=Methods.method_heuristic_initial_clusters_max_dist):
    win = GraphWin("Results", 800, 600)
    displacement = 20

    time_start = time()

    for point in points:
        p = GPoint(point.x * displacement, point.y * displacement)
        p.draw(win)

    iteration_result = Methods.clustering(points, number_of_clusters,
                                          max_iterations, method)

    clusters = iteration_result.clusters

    for c in clusters:
        c = Circle(
            GPoint(c.center.x * displacement, c.center.y * displacement),
            c.radius * displacement)
        c.draw(win)

    time_end = time()

    time_range = time_end - time_start

    print("-----------------------------")
    print("Method used: " + get_method_name(method))
    print("Total time: " + str(time_range) + " s")
    print("Results after " + str(max_iterations) + " iterations:")
    print(str(clusters))
    if solution is not None:
        errors = Methods.compare_results(clusters, solution)
        print("Max error: " + str(errors[1]))
        print("Min error: " + str(errors[2]))
        print("Median error: " + str(errors[0]))

    try:
        win.getMouse()
        win.close()
    except:
        return 0
Example #7
0
def undraw_entity(entity, win):
    if win is not None:
        p = Point(entity.x_pos, entity.y_pos)
        p.setOutline("red")
        p.draw(win)
Example #8
0
line = Line(p1, p2)
line.draw(win)

i = -3
while i <= 3:
    if i != 0:
        p1 = Point(trans_X(i), trans_Y(-0.1))
        teks = Text(p1, i)
        teks.draw(win)
    i = i + 1

i = -1
while i <= 5:
    if i != 0:
        p1 = Point(trans_X(0.05), trans_Y(i))
        teks = Text(p1, i)
        teks.draw(win)
    i = i + 1

x = float(-2)
while x <= 2:
    nx = x
    ny = x**2
    point = Point(trans_X(nx), trans_Y(ny))
    point.draw(win)
    update(2000)
    x = x + 0.001

win.getMouse()
win.close()
write()
Example #9
0
#-*- coding:utf-8-*-
from graphics import Point, GraphWin
p = Point(50, 60)
p.getX()
p.getY()
win = GraphWin()
p.draw(win)
p2 = Point(140, 160)
p2.draw(win)
Example #10
0
 def plot(self, x, y):
     _point = Point(x, y)
     _point.draw(self.window)