_
This commit is contained in:
parent
0006a4781c
commit
33d2fc169b
22
grad.py
Normal file
22
grad.py
Normal file
|
|
@ -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 ()
|
||||
43
main.py
Normal file
43
main.py
Normal file
|
|
@ -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("<Button-1>", on_mouse_click) # Левый клик мыши
|
||||
root.bind("<Return>", on_enter_pressed) # Клавиша Enter
|
||||
|
||||
|
||||
# Запускаем главный цикл обработки событий
|
||||
root.mainloop()
|
||||
39
vector.py
Normal file
39
vector.py
Normal file
|
|
@ -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
|
||||
Loading…
Reference in New Issue
Block a user