hypothenuse = Node(name='length of hypothenuse',
                   action=sqrt,
                   inputs=Node.inputs(area_hypothenuse))
sin_alpha = Node(name='sin of alpha',
                 action=operator.div,
                 inputs=Node.inputs(a, hypothenuse))
alpha = Node(name='angle alpha',
             action=math.asin,
             inputs=Node.inputs(sin_alpha))
sin_beta = Node(name='sin of beta',
                action=operator.div,
                inputs=Node.inputs(b, hypothenuse))
beta = Node(name='angle beta', action=math.asin, inputs=Node.inputs(sin_beta))

print 'Enter float values for a and b, e.g.\n> 3.0 4.0'
while True:
    answer = raw_input('\n> ')
    if not answer:
        break
    value_a, value_b = answer.split()
    update_inputs([(a, float(value_a)), (b, float(value_b))])
    print 'Length of hypothenuse: {:.2f}'.format(hypothenuse.value)
    print 'Angle alpha: {:.2f} degrees'.format(math.degrees(alpha.value))
    print 'Angle beta: {:.2f} degrees'.format(math.degrees(beta.value))

try:
    visualize_graph([hypothenuse], 'triangle.png')
    print 'View triangle.png to see a visualization of the traph.'
except OSError:
    print 'Please install graphviz to visualize the graph.'
Esempio n. 2
0
    return math.sqrt(square)


area_a = Node(name="square of a", action=square, inputs=Node.inputs(a))
area_b = Node(name="square of b", action=square, inputs=Node.inputs(b))
area_hypothenuse = Node(name="square of hypothenuse", action=sum_, inputs=Node.inputs(area_a, area_b))
hypothenuse = Node(name="length of hypothenuse", action=sqrt, inputs=Node.inputs(area_hypothenuse))
sin_alpha = Node(name="sin of alpha", action=operator.div, inputs=Node.inputs(a, hypothenuse))
alpha = Node(name="angle alpha", action=math.asin, inputs=Node.inputs(sin_alpha))
sin_beta = Node(name="sin of beta", action=operator.div, inputs=Node.inputs(b, hypothenuse))
beta = Node(name="angle beta", action=math.asin, inputs=Node.inputs(sin_beta))


print "Enter float values for a and b, e.g.\n> 3.0 4.0"
while True:
    answer = raw_input("\n> ")
    if not answer:
        break
    value_a, value_b = answer.split()
    update_inputs([(a, float(value_a)), (b, float(value_b))])
    print "Length of hypothenuse: {:.2f}".format(hypothenuse.value)
    print "Angle alpha: {:.2f} degrees".format(math.degrees(alpha.value))
    print "Angle beta: {:.2f} degrees".format(math.degrees(beta.value))


try:
    visualize_graph([hypothenuse], "triangle.png")
    print "View triangle.png to see a visualization of the traph."
except OSError:
    print "Please install graphviz to visualize the graph."
Esempio n. 3
0
    draw_circle(colors[alert.value])


def draw_circle(color):
    tx = TARGET['x']
    ty = TARGET['y']
    canvas.create_oval(tx - RADIUS, ty - RADIUS, tx + RADIUS, ty + RADIUS,
                       fill=color)


root = Tkinter.Tk()
frame = Tkinter.Frame(root)
frame.pack(fill=Tkinter.BOTH, expand=1)
canvas = Tkinter.Canvas(frame, background='white')
draw_circle('blue')
canvas.pack(fill=Tkinter.BOTH, expand=1)
canvas.pack()
canvas.bind("<Button-1>", onclick)
canvas.bind("<B1-Motion>", onclick)

try:
    visualize_graph([alert], 'mouse.gif')
    print 'View mouse.gif to see a visualization of the traph.'
    diagram = Tkinter.PhotoImage(file='mouse.gif')
    canvas.create_image(0, 2 * (TARGET['y'] + RADIUS),
                        image=diagram, anchor='nw')
except OSError:
    print 'Please install graphviz to visualize the graph.'

root.mainloop()
Esempio n. 4
0
    print
    colors = {"INSIDE": "red", "OUTSIDE": "blue"}
    draw_circle(colors[alert.value])


def draw_circle(color):
    tx = TARGET["x"]
    ty = TARGET["y"]
    canvas.create_oval(tx - RADIUS, ty - RADIUS, tx + RADIUS, ty + RADIUS, fill=color)


root = Tkinter.Tk()
frame = Tkinter.Frame(root)
frame.pack(fill=Tkinter.BOTH, expand=1)
canvas = Tkinter.Canvas(frame, background="white")
draw_circle("blue")
canvas.pack(fill=Tkinter.BOTH, expand=1)
canvas.pack()
canvas.bind("<Button-1>", onclick)
canvas.bind("<B1-Motion>", onclick)

try:
    visualize_graph([alert], "mouse.gif")
    print "View mouse.gif to see a visualization of the traph."
    diagram = Tkinter.PhotoImage(file="mouse.gif")
    canvas.create_image(0, 2 * (TARGET["y"] + RADIUS), image=diagram, anchor="nw")
except OSError:
    print "Please install graphviz to visualize the graph."

root.mainloop()