You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
2.6 KiB

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> ")
premtoken = input("Введите Premium-токен, если не хотите использовать токен просто нажмите Enter\n> ")
if premtoken!="":
tokenlimit = input("Введите лимит токена\n> ")
else:
token=False
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 *
if token==False:
draw(optimize(image, [255,255,255]) ) # Remove white background and draw
else:
draw(image, limit=tokenlimit, token=premtoken )