Загрузил(а) файлы в ''
This commit is contained in:
parent
d327ae0aa4
commit
9edd68cccc
91
bot.py
Normal file
91
bot.py
Normal file
@ -0,0 +1,91 @@
|
||||
import requests
|
||||
from time import sleep
|
||||
# Progress-bar
|
||||
from tqdm import tqdm
|
||||
# Work with list-like objects
|
||||
from listwork import *
|
||||
|
||||
from os import system
|
||||
print("Поместите файл картинки в папку с этим файлом.")
|
||||
coordbyx = input("Введите координату по X (по умолчанию - 0)\n> ")
|
||||
coordbyy = input("Введите координату по Y (по умолчанию - 0)\n> ")
|
||||
if coordbyx=="":
|
||||
coordbyx=0
|
||||
if coordbyy=="":
|
||||
coordbyy=0
|
||||
try:
|
||||
coordbyx=int(coordbyx)
|
||||
coordbyy=int(coordbyy)
|
||||
except:
|
||||
print("Цифрами, балбес.")
|
||||
system("pause")
|
||||
system("exit")
|
||||
# Easy debug
|
||||
from icecream import ic
|
||||
ic.disable() # Disable debug
|
||||
|
||||
global server
|
||||
#server = 'http://127.0.0.1:3333'
|
||||
server = 'http://pb.gulyaipole.fun'
|
||||
|
||||
# fill(0,0, 10,10, [0,0,0])
|
||||
def fill(x1,y1, x2,y2, color):
|
||||
pxls = []
|
||||
r = color[0] ; g = color[1] ; b = color[2]
|
||||
for x in range(x1, x2+1):
|
||||
for y in range(y1, y2+1):
|
||||
pxls.append([x, y, r, g, b])
|
||||
return pxls
|
||||
|
||||
# draw( fill(...) )
|
||||
def draw(pxls):
|
||||
global server
|
||||
ic(pxls)
|
||||
|
||||
push = [] # Push %limit% items
|
||||
limit = 300
|
||||
while len(pxls) > limit:
|
||||
packs = [] # Merge elements to %limit% size list
|
||||
for i in range(limit):
|
||||
# Take first element
|
||||
packs.append(pxls[0])
|
||||
pxls.pop(0)
|
||||
push.append({"main": pack(packs)})
|
||||
push.append({"main": pack(pxls)}) # Pack last
|
||||
|
||||
ic(push)
|
||||
for i in tqdm(push):
|
||||
response = requests.post(server, i)
|
||||
while not response.status_code == 200:
|
||||
print("Error, retrying...")
|
||||
response = requests.post(server, i)
|
||||
sleep(0.1)
|
||||
|
||||
# cfill(0,0, 10,10) // Limit - 34x34
|
||||
def cfill(x1,y1, x2,y2):
|
||||
pxls = []
|
||||
for x in range(x1, x2+1):
|
||||
for y in range(y1, y2+1):
|
||||
pxls.append([x, y])
|
||||
packed = pack(pxls)
|
||||
return packed
|
||||
|
||||
# ccheck( packed([[0,0]]) ) or ccheck(cfill(...))
|
||||
def ccheck(packed):
|
||||
global server
|
||||
response = requests.get(f'{server}/get_color={packed}')
|
||||
ic(response.text)
|
||||
out = unpack(response.text)
|
||||
return out
|
||||
|
||||
|
||||
# Draw image (flipped (BUG) )
|
||||
from im_convert import *
|
||||
try:
|
||||
image = convert("image.png", [coordbyx,coordbyy])
|
||||
except:
|
||||
print('Файл картинки отсутствует, или назван не "image.png"')
|
||||
system('pause')
|
||||
system('exit')
|
||||
from remove_back import *
|
||||
draw(optimize(image, [255,255,255]) ) # Remove white background and draw
|
23
bot_extras.py
Normal file
23
bot_extras.py
Normal file
@ -0,0 +1,23 @@
|
||||
from listwork import *
|
||||
from random import randint as ri
|
||||
|
||||
# pas2( fill(...) ) -> 1/2
|
||||
def pas2(pxls):
|
||||
new_pxls = []
|
||||
|
||||
pas = False
|
||||
for i in pxls:
|
||||
if not pas:
|
||||
new_pxls.append(i)
|
||||
pas = True
|
||||
else:
|
||||
pas = False
|
||||
return new_pxls
|
||||
|
||||
# rand(x1,y1, x2,y2) -> draw() or pas2()
|
||||
def rand(x1,y1, x2,y2):
|
||||
pxls = []
|
||||
for x in range(x1, x2 +1):
|
||||
for y in range(y1, y2 +1):
|
||||
pxls.append([x,y, ri(0,255), ri(0,255), ri(0,255)])
|
||||
return pxls
|
42
gpt_blob.py
Normal file
42
gpt_blob.py
Normal file
@ -0,0 +1,42 @@
|
||||
import tkinter as tk
|
||||
from time import sleep
|
||||
|
||||
def start_drag(event):
|
||||
global current_coords
|
||||
global dragged_item
|
||||
dragged_item = label
|
||||
current_coords = label.winfo_pointerx(), label.winfo_pointery()
|
||||
|
||||
def stop_drag(event):
|
||||
dragged_item = None
|
||||
|
||||
def drag(event):
|
||||
global current_coords
|
||||
xc, yc = label.winfo_pointerx(), label.winfo_pointery()
|
||||
dx, dy = xc - current_coords[0], yc - current_coords[1]
|
||||
current_coords = xc, yc
|
||||
label.place(x=label.winfo_x() + dx, y=label.winfo_y() + dy)
|
||||
|
||||
def nn(root,im):
|
||||
global label
|
||||
|
||||
image = tk.PhotoImage(file=im) # Use self.image
|
||||
label = tk.Label(root, image=image)
|
||||
label.image = image # Keep a reference to the image
|
||||
label.pack()
|
||||
|
||||
dragged_item = None
|
||||
current_coords = 0, 0
|
||||
|
||||
label.bind('<ButtonPress-1>', start_drag)
|
||||
label.bind('<ButtonRelease-1>', stop_drag)
|
||||
label.bind('<B1-Motion>', drag)
|
||||
# globals().update(locals())
|
||||
|
||||
while True:
|
||||
tk.Misc.lift(label)
|
||||
sleep(0.05)
|
||||
|
||||
print("Image cords: ", label.winfo_x(), 670 - label.winfo_y())
|
||||
#x1, y1 = image.coords(image)
|
||||
# print(f'Image cords: {}')
|
52
im_convert.py
Normal file
52
im_convert.py
Normal file
@ -0,0 +1,52 @@
|
||||
from PIL import Image, ImageOps
|
||||
|
||||
# [[0,0, rgb1],... [1,1, rgb2]] -> [[1,1, rgb1],...[0,0, rgb2]]
|
||||
def flip(cords):
|
||||
fliped = []
|
||||
flips = len(cords)//2
|
||||
|
||||
# El from start and el from end
|
||||
fl0 = 0 ; fl1 = len(cords)-1
|
||||
|
||||
for i in range(flips):
|
||||
# Copy element and change cords to cords of end element
|
||||
new_st = list(cords[fl0])
|
||||
new_st[0] = cords[fl1][0]
|
||||
new_st[1] = cords[fl1][1]
|
||||
fliped.append(new_st)
|
||||
|
||||
# Copy and change cords to cords of start element
|
||||
new_end = list(cords[fl1])
|
||||
new_end[0] = cords[fl0][0]
|
||||
new_end[1] = cords[fl0][1]
|
||||
fliped.append(new_end)
|
||||
|
||||
fl0 += 1 ; fl1 -= 1
|
||||
|
||||
return fliped
|
||||
|
||||
# convert("example.png") // png/jpg/gif
|
||||
def convert(filename, move = [0,0]):
|
||||
im = Image.open(filename).convert('RGB')
|
||||
# Fix mirror
|
||||
im = ImageOps.mirror(im)
|
||||
pxls=im.load()
|
||||
w=im.size[0]
|
||||
h=im.size[1]
|
||||
|
||||
ll = []
|
||||
for x in range(w):
|
||||
for y in range(h):
|
||||
# [x,y, [r, g, b]]
|
||||
rgb = pxls[x,y]
|
||||
ll.append( [x,y, rgb[0], rgb[1], rgb[2] ] )
|
||||
|
||||
# Fix flip
|
||||
fliped = flip(ll)
|
||||
|
||||
# Move [x,y] + move
|
||||
moved = []
|
||||
for i in fliped:
|
||||
moved.append([i[0] + move[0], i[1] + move[1], i[2],i[3],i[4]])
|
||||
|
||||
return moved
|
24
listwork.py
Normal file
24
listwork.py
Normal file
@ -0,0 +1,24 @@
|
||||
def unpack(string):
|
||||
ll = string.split('-_')
|
||||
ll.remove("") # Remove empty line
|
||||
el_col = ll[0].count('-')
|
||||
|
||||
post_ll = []
|
||||
for i in ll:
|
||||
temp = i.split("-")
|
||||
# Multi-add (2, 3 or 5 elements)
|
||||
if el_col == 1:
|
||||
post_ll.append([int(temp[0]), int(temp[1])])
|
||||
elif el_col == 2:
|
||||
post_ll.append([int(temp[0]), int(temp[1]), int(temp[2])])
|
||||
elif el_col == 4:
|
||||
post_ll.append([int(temp[0]), int(temp[1]), int(temp[2]), int(temp[3]), int(temp[4]) ])
|
||||
return post_ll
|
||||
|
||||
def pack(ll):
|
||||
string = ''
|
||||
for el in ll:
|
||||
for i in el:
|
||||
string += str(i) + '-'
|
||||
string += '_'
|
||||
return string
|
Loading…
Reference in New Issue
Block a user