Exemplo n.º 1
0
def drawPoints(x, y, canvas):
	hTable = readConfig()
	width = int(hTable['width'])
	height = int(hTable['height'])
	scale = width / (float(DocumentDictionary.getUpperBound()) - (float(DocumentDictionary.getLowerBound())))
	X = []
	Y = []
	for i in range(len(x)):
		if isinstance(y[i], (int, float)):
			X.append(x[i] * scale + width/2)
			Y.append(-y[i] * scale + height/2)
			#draws points, uncomment to enable
			#canvas.create_oval(X[i], Y[i], X[i], Y[i])

	global currentColour

	for i in range(len(X) - 1):
		canvas.create_line(X[i], Y[i], X[i+1], Y[i+1], fill=colours[currentColour], width=2)
	if Y[0] <= 0:
		Y[0] = 40
	if Y[0] >= float(height):
		Y[0] = height - 40
	canvas.create_text(X[0] + 30,Y[0] - 10, text= (DocumentDictionary.getType()),fill=colours[currentColour])

	if currentColour == 6:
		currentColour = 0;
	else:
		currentColour = currentColour + 1
Exemplo n.º 2
0
def div(left, right):
    # TODO: division by zero to be tested
    try:
        result = left / right
        return result
    except ZeroDivisionError:
        DocumentDictionary.setProcessError(False)
        return None
Exemplo n.º 3
0
def closeSettings(window, graphCanvas):
    hTable = readConfig()
    graphCanvas.delete("all")
    graphCanvas.configure(height=hTable['height'], width=hTable['width'])
    drawLines(graphCanvas)
    if hTable['mode'] == "radians":
        DocumentDictionary.setRad(True)
    else:
        DocumentDictionary.setRad(False)
    window.destroy()
Exemplo n.º 4
0
def process(tree, nodeIndex):
    # security layer and domain out of bound handling
    try:
        if tree[Tree.leftChildIndex(nodeIndex)] != None:
            left = float(tree[Tree.leftChildIndex(nodeIndex)])
        else:
            left = None
        if tree[Tree.rightChildIndex(nodeIndex)] != None:
            right = float(tree[Tree.rightChildIndex(nodeIndex)])
        else:
            right = None

        parent = tree[nodeIndex]
        result = calculate(parent, left, right)
        tree[nodeIndex] = result
        Tree.removeChilds(tree, nodeIndex)

    except ValueError, e:
        if (e.message == "math domain error"):
            DocumentDictionary.setProcessError(False)
Exemplo n.º 5
0
def drawLines(canvas):
	hTable = readConfig()
	width = int(hTable['width'])
	height = int(hTable['height'])
	scale = width / ((float(DocumentDictionary.getUpperBound()) - (float(DocumentDictionary.getLowerBound()))) / float(DocumentDictionary.getScale()))
	horLine= canvas.create_line(0, height/2, width, height/2, fill="black")
	vertLine = canvas.create_line(width/2, 0, width/2, height, fill="black")

	for x in range(0, width, int(scale)):
		canvas.create_line(x,height/2 + 4,x,height/2 -4, fill="black")

	canvas.create_text(10 ,height / 2 + 10, text= DocumentDictionary.getLowerBound(), tag = "c**t")
	canvas.create_text(width - 10 ,height / 2 + 10, text= DocumentDictionary.getUpperBound(), tag = "c**t")

	for y in range(0, height, int(scale)):
		canvas.create_line(width/2 + 4, y, width/2 -4,y, fill="black")
	canvas.create_text(width/2 + 10, 10, text= DocumentDictionary.getUpperBound(), tag = "c**t")
	canvas.create_text(width/2 + 10, height - 10, text= DocumentDictionary.getLowerBound(), tag = "c**t")
Exemplo n.º 6
0
def generateGraph(graphCanvas, settingsFrame, op, var, root, entry, minRange,
                  maxRange, interval):
    boldFont = tkFont.Font(weight="bold")
    hTable = readConfig()
    if checkRanges(minRange, maxRange):
        DocumentDictionary.setUpperBound(maxRange)
        DocumentDictionary.setLowerBound(minRange)
        DocumentDictionary.setScale(interval)
        DocumentDictionary.setType(entry)
        DocumentDictionary.setAnswer(None)
        errorCode = goRunAll(entry)
        if errorCode is 0:
            if DocumentDictionary.getAnswer() is None:
                graph(graphCanvas)
                op.append(entry)
                history = apply(OptionMenu, (settingsFrame, var) + tuple(op))
                history.configure(highlightbackground="#000000")
                history.grid(row=0, column=0)
                errorVar.set("")
            else:
                answer.set("ANSWER: " + str(DocumentDictionary.getAnswer()))
        else:
            showError(getErrorMsg(errorCode))
    return
Exemplo n.º 7
0
def graph(canvas):
	canvas.delete("c**t")
	x = DocumentDictionary.getTableOfValues()['xValues']
	y = DocumentDictionary.getTableOfValues()['yValues']
	drawLines(canvas)
	drawPoints(x, y, canvas)
Exemplo n.º 8
0
def arctangente(left, right):
    if DocumentDictionary.isRad():
        return math.atan(left)
    else:
        return math.atan(math.radians(left))
Exemplo n.º 9
0
def arccosinus(left, right):
    if DocumentDictionary.isRad():
        return math.acos(left)
    else:
        return math.acos(math.radians(left))
Exemplo n.º 10
0
def sinus(left, right):
    if DocumentDictionary.isRad():
        return math.sin(left)
    else:
        return math.sin(math.radians(left))
Exemplo n.º 11
0
def arcsinhyp(left, right):
    if DocumentDictionary.isRad():
        return math.asinh(left)
    else:
        return math.asinh(math.radians(left))
Exemplo n.º 12
0
def coshyp(left, right):
    if DocumentDictionary.isRad():
        return math.cosh(left)
    else:
        return math.cosh(math.radians(left))