def onclick(event): update_inputs([(mousex, event.x), (mousey, event.y)]) print "distance.value == {:.1f}".format(distance.value) print "is_close.value == {!r}".format(is_close.value) print "alert.value == {!r}".format(alert.value) print colors = {"INSIDE": "red", "OUTSIDE": "blue"} draw_circle(colors[alert.value])
def onclick(event): update_inputs([(mousex, event.x), (mousey, event.y)]) print 'distance.value == {:.1f}'.format(distance.value) print 'is_close.value == {!r}'.format(is_close.value) print 'alert.value == {!r}'.format(alert.value) print colors = {'INSIDE': 'red', 'OUTSIDE': 'blue'} draw_circle(colors[alert.value])
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.'
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."
return x - y class Addition(Fragment): def build_fragment(self, x, y): return x + y class Power(Fragment): def build_fragment(self, x, p): return x**p x = Input(name='x-value') y = Input(name='y-value') p = Input(name='power') difference = Difference(inputs=Node.inputs(x, y)) difference2 = Difference(inputs=Node.inputs(p, p)) addition = Addition(inputs=Node.inputs(difference, difference2)) power = Power(inputs=Node.inputs(difference, p)) update_inputs([(p, 10), (x, 5), (y, 10)]) # print power.value print addition.value print "changing y" update_inputs([(y, 5)]) print addition.value