If you don’t know what Python is, its a coding language, and I made a simple graphing calculator that can plot simple quadratics, linear, and implict equation. And yes, I used AI for a bit of my project
(for the graphing part, since it is pretty far beyond my brain)
Its is very slow. Sometimes, if the equation is complex, like y=1/x, it will have many gaps and half the curve won’t render.
This shows how impressive of a project Desmos is. It can plot a curve in milliseconds with unbelievable accuracy (well a big reason is cause it has like a GPU but I’m just using a brute-force technique which runs at like O(n^9999)). Enjoy!
(To install numpy, use pip install numpy)
import turtle as t
import numpy as np
DISTANCE = 20
GRAPH_RANGE = 20
screen = t.Screen()
t.speed(0)
t.pensize(3)
def takeInput():
exp = input("Enter equation: ")
return exp.split("=")
def parse(exp):
result = ["", ""]
for side in [0, 1]:
text = exp[side]
for i, c in enumerate(text):
if c in "xy":
if i > 0 and (text[i - 1].isdigit() or text[i - 1] in "xy"):
result[side] += "*"
result[side] += c
else:
result[side] += c
result[0] = result[0].replace("^", "**")
result[1] = result[1].replace("^", "**")
return result
def draw_axes(axis_len=400):
t.hideturtle()
t.pensize(2)
t.penup()
t.goto(-axis_len, 0)
t.pendown()
t.goto(axis_len, 0)
t.penup()
t.goto(0, -axis_len)
t.pendown()
t.goto(0, axis_len)
for x in range(-axis_len, axis_len + 1, DISTANCE):
t.penup()
t.goto(x, -5)
t.pendown()
t.goto(x, 5)
for y in range(-axis_len, axis_len + 1, DISTANCE):
t.penup()
t.goto(-5, y)
t.pendown()
t.goto(5, y)
t.penup()
def solve(exp):
lhs, rhs = parse(exp)
xs = np.linspace(-GRAPH_RANGE, GRAPH_RANGE, 2000)
t.penup()
for x in xs:
ys = np.linspace(-GRAPH_RANGE, GRAPH_RANGE, 200)
for y in ys:
try:
if abs(eval(lhs) - eval(rhs)) < 0.01:
screen_x = x * DISTANCE
screen_y = y * DISTANCE
t.goto(screen_x, screen_y)
t.pendown()
except Exception:
pass
draw_axes()
equation = takeInput()
solve(equation)
t.done()