def clear_func(widget): global eqns try: if widget == clearf: del graphcmd.graphs['f'] graphcmd.main('s', graphcmd.opt) for widget in [fxinttext, fyinttext, fslopetext, fvalueoutput]: widget.value(0) else: del graphcmd.graphs['g'] graphcmd.main('s', graphcmd.opt) for widget in [gxinttext, gyinttext, gslopetext, gvalueoutput]: widget.value(0) except KeyError: pass graph.image(Fl_PNG_Image('graph.png')) window.redraw()
def update_setting(): global flinecolor, glinecolor optdict = {7: 'xmin', 8: 'xmax', 9: 'ymin', 10: 'ymax', 11: 'xscl', 12: 'yscl', 13: 'point', 14: 'tick', 15: 'drawaxes', 16: 'axes', 17: 'axescolor', 18: 'grid', 19: 'backg'} newopt = {} with open('config.txt') as config: lcount = 0 for configline in config: if lcount == 5: colortup = configline.split(' : ')[1] exec('flinecolor = ' + colortup, globals()) elif lcount == 6: colortup = configline.split(' : ')[1] exec('glinecolor = ' + colortup, globals()) elif lcount >= 7: exec('change = ' + configline.split(' : ')[1]) newopt[optdict[lcount]] = change lcount = lcount + 1 graphcmd.main('s', newopt)
def update_eqn(widget): global eqn try: if widget in [finterbutton, fpointbutton, fgenbutton]: if widget == finterbutton: slope, inter = fintslope.value(), fintinter.value() eqn = line.Linear('', [slope, inter]) elif widget == fpointbutton: y1, x1 = fpointy1.value(), fpointx1.value() eqn = line.Linear('p', [y1, fpointslope.value(), x1]) else: a, b, c = fgena.value(), fgenb.value(), fgenc.value() eqn = line.Linear('g', [a, b, c]) else: if widget == ginterbutton: slope, inter = gintslope.value(), gintinter.value() eqn = line.Linear('', [slope, inter]) elif widget == gpointbutton: y1, x1 = gpointy1.value(), gpointx1.value() eqn = line.Linear('p', [y1, gpointslope.value(), x1]) else: a, b, c = ggena.value(), ggenb.value(), ggenc.value() eqn = line.Linear('g', [a, b, c]) except: graph.label('Error: Check that coefficients are properly entered.') graph.image(None) graph.redraw() return if widget in [finterbutton, fpointbutton, fgenbutton]: fxinttext.value(eqn.xint()) fyinttext.value(eqn.yint()) fslopetext.value(eqn.slope()) if widget != finterbutton: fintslope.value(str(eqn.slope())) fintinter.value(str(eqn.yint())) if widget != fpointbutton: coefs = [str(n) for n in eqn.pointform()] fpointy1.value(coefs[0]) fpointslope.value(coefs[1]) fpointx1.value(coefs[2]) if widget != fgenbutton: coefs = [str(n) for n in eqn.generalform()] fgena.value(coefs[0]) fgenb.value(coefs[1]) fgenc.value(coefs[2]) else: gxinttext.value(eqn.xint()) gyinttext.value(eqn.yint()) gslopetext.value(eqn.slope()) if widget != ginterbutton: gintslope.value(str(eqn.slope())) gintinter.value(str(eqn.yint())) if widget != gpointbutton: coefs = [str(n) for n in eqn.pointform()] gpointy1.value(coefs[0]) gpointslope.value(coefs[1]) gpointx1.value(coefs[2]) if widget != ggenbutton: coefs = [str(n) for n in eqn.generalform()] ggena.value(coefs[0]) ggenb.value(coefs[1]) ggenc.value(coefs[2]) update_setting() if widget in [finterbutton, fpointbutton, fgenbutton]: graphcmd.graphs['f'] = (eqn, flinecolor) else: graphcmd.graphs['g'] = (eqn, glinecolor) graphcmd.main('s', graphcmd.opt) graph.label(None) graph.image(Fl_PNG_Image('graph.png')) if len(graphcmd.graphs) == 2: eqna, eqnb = graphcmd.graphs['f'][0], graphcmd.graphs['g'][0] solution.value(str(line.LinearSystem(eqna, eqnb).xint())) window.redraw()
exec('glinecolor = ' + colortup, globals()) elif lcount >= 7: exec('change = ' + configline.split(' : ')[1]) newopt[optdict[lcount]] = change lcount = lcount + 1 graphcmd.main('s', newopt) def setopt(widget, align, value, font=None): widget.align(align) widget.value(value) if font is not None: widget.labelfont(font) graphcmd.main('i', 'graph.png') update_setting() window = Fl_Window(50, 50, 1250, 671, 'Linear Equation Analysis') window.color(fl_rgb_color(247, 247, 247)) window.begin() setbutton = Fl_Button(1160, 635, 80, 25, 'Settings') setbutton.color(fl_rgb_color(230, 230, 230)) setbutton.callback(settings_window) fxtext = Fl_Box(589, 20, 0, 0, 'f(x)') fxtext.labelfont(FL_BOLD) finttext = Fl_Box(637, 40, 50, 20, 'Slope-intercept form:\ty = ')