summaryrefslogtreecommitdiff
path: root/python-graphics/main.py
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 /python-graphics/main.py
parentc763f723095ada3fc1c683929a410ef533cfa93d (diff)
Добавил sin и cos в предустановленные функции
Diffstat (limited to 'python-graphics/main.py')
-rw-r--r--python-graphics/main.py36
1 files changed, 35 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",