From efa32bdc3fc03264272acc10216b891e2f7916d6 Mon Sep 17 00:00:00 2001 From: Andrew Guschin Date: Tue, 6 Apr 2021 14:58:29 +0400 Subject: =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20sin=20?= =?UTF-8?q?=D0=B8=20cos=20=D0=B2=20=D0=BF=D1=80=D0=B5=D0=B4=D1=83=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D0=B5=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python-graphics/main.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'python-graphics/main.py') 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", -- cgit v1.2.3