summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Guschin <saintruler@gmail.com>2021-04-06 14:58:29 +0400
committerAndrew Guschin <saintruler@gmail.com>2021-04-06 14:58:29 +0400
commitefa32bdc3fc03264272acc10216b891e2f7916d6 (patch)
tree9d1e9622ff85439651a8399feccead2c8972ce70
parentc763f723095ada3fc1c683929a410ef533cfa93d (diff)
Добавил sin и cos в предустановленные функции
-rw-r--r--python-graphics/main.py36
-rw-r--r--python-graphics/plotter.py6
2 files changed, 41 insertions, 1 deletions
diff --git a/python-graphics/main.py b/python-graphics/main.py
index 177bf3f..a21cc1b 100644
--- a/python-graphics/main.py
+++ b/python-graphics/main.py
@@ -26,10 +26,12 @@ class GraphMode:
class PresetType:
LINE = "ax + b = 0"
PARABOLA = "ax^2 + bx + c = 0"
+ SIN = "a * sin(b * x + c)"
+ COS = "a * cos(b * x + c)"
@classmethod
def options(cls):
- return [cls.LINE, cls.PARABOLA]
+ return [cls.LINE, cls.PARABOLA, cls.SIN, cls.COS]
class PlotTypeFrame(tk.Frame):
@@ -108,6 +110,8 @@ class PresetPlotFrame(tk.Frame):
# скрывать.
self.variables[PresetType.LINE] = [(la, a), (lb, b)]
self.variables[PresetType.PARABOLA] = [(la, a), (lb, b), (lc, c)]
+ self.variables[PresetType.SIN] = [(la, a), (lb, b), (lc, c)]
+ self.variables[PresetType.COS] = [(la, a), (lb, b), (lc, c)]
self.variables[None] = [(la, a), (lb, b), (lc, c)]
# Изменения этой переменной будут передаваться в метод type_changed
@@ -176,6 +180,36 @@ class PresetPlotFrame(tk.Frame):
"b": b,
"c": c
}
+ elif cur_type == PresetType.SIN:
+ try:
+ c = float(v[2][1].get().strip())
+ except ValueError:
+ return {"status": "error", "message": "c не является float"}
+ return {
+ "status": "ok",
+ "graph": "preset",
+ "type": "sin",
+ "min": min_x,
+ "max": max_x,
+ "a": a,
+ "b": b,
+ "c": c
+ }
+ elif cur_type == PresetType.COS:
+ try:
+ c = float(v[2][1].get().strip())
+ except ValueError:
+ return {"status": "error", "message": "c не является float"}
+ return {
+ "status": "ok",
+ "graph": "preset",
+ "type": "cos",
+ "min": min_x,
+ "max": max_x,
+ "a": a,
+ "b": b,
+ "c": c
+ }
elif cur_type == PresetType.LINE:
return {
"status": "ok",
diff --git a/python-graphics/plotter.py b/python-graphics/plotter.py
index 6ab8275..32d96b2 100644
--- a/python-graphics/plotter.py
+++ b/python-graphics/plotter.py
@@ -17,6 +17,12 @@ def plot_preset(data):
y = a * x**2 + b * x + c
elif data["type"] == "line":
y = a * x + b
+ elif data["type"] == "sin":
+ c = data["c"]
+ y = a * np.sin(b * x + c)
+ elif data["type"] == "cos":
+ c = data["c"]
+ y = a * np.cos(b * x + c)
# setting the axes at the centre
fig = plt.figure()