diff --git a/grad.py b/grad.py new file mode 100644 index 0000000..7dc1dcb --- /dev/null +++ b/grad.py @@ -0,0 +1,22 @@ +from vector import Vector +from typing import Tuple, List + +def interpol(points: List[Tuple[int]]) -> List[Tuple[int]]: + n = len(points) + X = tuple(point[0] for point in points) + Y = tuple(point[1] for point in points) + graph = [] + for t in range(points[0][0], points[n-1][0]+1): + y = 0 + for i in range(n): + q = Y[i] + for j in range(n): + if j != i: + q = q * (t-X[j]) / (X[i] - X[j]) + y = y + q + graph.append((t, y)) + return graph + + +def main(points: List[Tuple[int]], colors: Tuple[Vector]) -> Tuple[int]: + return () \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..41f264e --- /dev/null +++ b/main.py @@ -0,0 +1,43 @@ +import tkinter as tk +from grad import interpol + +def rgb_to_hex(color): + r, g, b = color + return f'#{r:02x}{g:02x}{b:02x}' + +# Создаем основное окно +root = tk.Tk() +root.title("Pixel Coloring") + +# Устанавливаем размеры окна +width = 400 +height = 400 + +# Создаем холст (Canvas) для рисования +canvas = tk.Canvas(root, width=width, height=height) +canvas.pack() + +# Массив для хранения координат точек +points = [] + +# Функция, которая будет вызвана при нажатии Enter +def on_enter_pressed(event): + graph = interpol(points) + for x, y in graph: + canvas.create_line(x, y, x+1, y, fill=rgb_to_hex((0, 0, 0))) + +# Функция, которая вызывается при нажатии мыши +def on_mouse_click(event): + x, y = event.x, event.y + points.append((x, y)) # Добавляем координаты в массив + print(f"Point added: ({x}, {y})") + # Рисуем точку на холсте + canvas.create_oval(x - 3, y - 3, x + 3, y + 3, fill="red") + +# Привязываем события +canvas.bind("", on_mouse_click) # Левый клик мыши +root.bind("", on_enter_pressed) # Клавиша Enter + + +# Запускаем главный цикл обработки событий +root.mainloop() \ No newline at end of file diff --git a/vector.py b/vector.py new file mode 100644 index 0000000..d63e899 --- /dev/null +++ b/vector.py @@ -0,0 +1,39 @@ +class Vector(): + def __init__(self, *comps): + self.len = len(comps) + self.comps = comps + + def __add__(self, other): + if type(self) == type(other): + if self.len == other.len: + return Vector(*(self.comps[i] + other.comps[i] for i in range(self.len))) + else: + return "Длины должны совпадать" + + def __sub__(self, other): + if type(self) == type(other): + if self.len == other.len: + return Vector(*(self.comps[i] - other.comps[i] for i in range(self.len))) + else: + return "Длины должны совпадать" + + def __neg__(self): + return Vector(*(-self.comps[i] for i in range(self.len))) + + def __str__(self): + return '(' + ', '.join(map(str, self.comps)) + ')' + + def __mul__(self, other): + if type(other) == Vector: + if self.len == other.len: + return sum((self.comps[i]*other.comps[i] for i in range(self.len))) + else: + return "Длины должны совпадать" + if type(other) == int: + return Vector(*(self.comps[i] * other for i in range(self.len))) + + def __round__(self): + return Vector(*(round(self.comps[i]) for i in range(self.len))) + + def tuple(self): + return self.comps \ No newline at end of file