From 33ea452a8c14810c418d42b0b17b33e108dacb3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A5=D0=BE=D0=BB=D0=B8=D0=BD=D0=B8=D0=BC=D1=87=D0=B5?= =?UTF-8?q?=D0=BA?= Date: Sun, 26 Nov 2023 22:00:57 +0300 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=B8?= =?UTF-8?q?=D0=BB(=D0=B0)=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B2=20''?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- map.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ post.py | 19 ++++++++++++++ remove_back.py | 16 ++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 map.py create mode 100644 post.py create mode 100644 remove_back.py diff --git a/map.py b/map.py new file mode 100644 index 0000000..95f7b0f --- /dev/null +++ b/map.py @@ -0,0 +1,69 @@ +import urllib.request +import time +from PIL import Image, ImageTk +import io +import tkinter as tk + +url = "https://pb.gulyaipole.fun/" + +root = tk.Tk() +root.geometry("1280x720") + +# Canvas for image +canvas = tk.Canvas(root) +canvas.pack() + +# XY cords +ttext = tk.Canvas(root, width=100, height=20, bg="black") +ttext.place(x=1180, y=0) +text = ttext.create_text(50, 10, text="X: 1, Y: 1", fill="white") + +# Run threads +from threading import Thread +from time import sleep + +def cords_up(): + while True: + x = root.winfo_pointerx() - root.winfo_rootx() + y = 720 - (root.winfo_pointery() - root.winfo_rooty()) + ttext.itemconfig(text, text=f"X: {x}, Y: {y}") + sleep(0.05) + +cords = Thread(target=cords_up) +cords.start() + +def image_up(): + global canvas_old, canvas + + while True: + # Prepare image for tkiner + image_file = io.BytesIO(urllib.request.urlopen(url).read()) + img = Image.open(image_file) + tk_img = ImageTk.PhotoImage(img) + + # Create new canvas + canvas = tk.Canvas(root, width=img.size[0], height=img.size[1]) + canvas.create_image(0, 0, anchor="nw", image=tk_img) + canvas.place(x=0, y=0) + + try: + # New canvas and cords up + tk.Misc.lift(canvas) + tk.Misc.lift(ttext) + # Update + root.update() + sleep(2) + # Remove ols + canvas_old.destroy() + except: + pass + # New canvas now is old + canvas_old = canvas + +image = Thread(target=image_up) +image.start() + + + +root.mainloop() + diff --git a/post.py b/post.py new file mode 100644 index 0000000..d9cddce --- /dev/null +++ b/post.py @@ -0,0 +1,19 @@ +import requests +# Work with list-like objects +from listwork import * + +server = 'http://127.0.0.1:3333' + +# Draw some pixels +# [[x, y, color-1, color-2, color-3], ...] +fill = {"main": pack([[200, 100, 0, 0, 0], [15, 30, 255, 54, 43]]) } +response = requests.post(server, data=fill) +if response: + print("posted") + +# Get color code of coords +# [[x,y], ...] +xys = pack([[200,100], [13,10], [50,50]]) +response = requests.get(f'{server}/get_color={xys}') +print( unpack(response.text) ) + diff --git a/remove_back.py b/remove_back.py new file mode 100644 index 0000000..5163da4 --- /dev/null +++ b/remove_back.py @@ -0,0 +1,16 @@ +from tqdm import tqdm + +def optimize(pxls, back): + old_len = len(pxls) + + new_pxls = [] + for i in tqdm(range(old_len)): + el = pxls[i] + now_back = [el[2], el[3], el[4]] + + if now_back != back: + new_pxls.append(pxls[i]) + + print(f"Optimized {(old_len - len(new_pxls)) / old_len * 100 }%") + + return new_pxls