Compare commits

..

22 Commits

Author SHA1 Message Date
justuser31 1b415d50c5 Merge branch 'main' of ssh://ssh.dmcraft.online:2222/justuser/pxl_oboard 2023-04-21 20:48:40 +03:00
justuser31 4f5e14e131 Pass colored pixels 2023-04-21 20:48:27 +03:00
Your Name 380930e8e7 Fix colors 2023-04-21 20:40:58 +03:00
justuser31 df06ca94a3 Revert 2023-04-21 20:22:39 +03:00
justuser31 f5ed42c5e6 Revert 2023-04-21 20:22:17 +03:00
justuser31 74ad0ad523 Revert x y 2023-04-21 20:17:44 +03:00
justuser31 16930a2770 Init get_color 2023-04-21 20:14:38 +03:00
justuser31 3ad7d6f6fc Remove delay 2023-04-21 18:32:50 +03:00
justuser31 855e80f6e5 Remove borders 2023-04-21 18:32:25 +03:00
justuser31 f87c84db30 Add draw line 2023-04-21 17:19:58 +03:00
justuser31 10dab6a7f5 Merge branch 'main' of ssh://ssh.dmcraft.online:2222/justuser/pxl_oboard 2023-04-21 16:51:44 +03:00
justuser31 864a07cd89 Add move at X and Y 2023-04-21 16:50:46 +03:00
justuser 67762fda4a Update 'README.md' 2023-04-21 16:11:45 +03:00
justuser31 c8c6b2f405 Merge branch 'main' of ssh://ssh.dmcraft.online:2222/justuser/pxl_oboard 2023-04-21 16:06:37 +03:00
justuser31 ae874feb75 Add x and y move in draw() 2023-04-21 16:06:24 +03:00
justuser d3b4728c3c Update 'README.md' 2023-04-21 15:44:32 +03:00
justuser31 99ec1d099d Wait after error and no wait before request 2023-04-21 15:41:35 +03:00
justuser31 9a83760295 Compatibility for python 3.7 2023-04-21 15:19:23 +03:00
justuser31 e0995302eb Compatibility for python 3.7 2023-04-21 15:16:53 +03:00
justuser31 33c335b001 Add progress bar 2023-04-21 13:01:59 +03:00
justuser31 35574ef69f Merge branch 'main' of ssh://ssh.dmcraft.online:2222/justuser/pxl_oboard 2023-04-21 12:55:44 +03:00
justuser31 3b72176d9c Add fill() and progress bar 2023-04-21 12:55:30 +03:00
5 changed files with 138 additions and 70 deletions
+3 -1
View File
@@ -19,11 +19,13 @@ Super simple, super stupid.
Вы можете написать свой скрипт на основе post.py или...
1. Скачать bot.py
2. Запрогроммировать свои инструкции для бота:
#### draw([0,1], [0,2]) - Функция для рисования, использует массив списков.
#### draw([0,1], [0,2], "blue") - Функция для рисования, использует массив списков.
( Поставить точки в координатах [0,1] и [0,2] формата [x,y] )
#### linex(y, x1, x2) - Функция для создания массива линии по координате Х
( Y остаётся таким же, массив идёт из x1 в x2 )
#### liney(x, y1, y2) - Аналогично.
#### fill([x1,y1], [x2, y2]) - Генерация массива для заполнения, дальше передавать в draw()
#### xc - Смещение по X ; yc - Смещение по Y
## --------------------------------
## Установка своего сервера:
+38 -29
View File
@@ -1,21 +1,31 @@
import requests
from time import sleep
from tqdm import tqdm
def draw(cords):
for i in range(len(cords)):
sleep(0.2)
global xc, yc
xc = 0 ; yc = 0
def gcolor(x, y):
response = requests.get(f'http://pb.dmcraft.online/?get_color={x},{y}')
return response.text
def draw(cords, color = "black"):
global xc, yc
for i in tqdm(range(len(cords))):
try:
payload = {'x': cords[i][1], 'y': cords[i][0], 'color': cords[i][2]}
color = cords[i][2]
except:
payload = {'x': cords[i][1], 'y': cords[i][0], 'color': "blue" }
pass
if str(gcolor(cords[i][1], cords[i][0])) != color:
payload = {'x': cords[i][1] + yc, 'y': cords[i][0] + xc, 'color': color }
response = requests.post('http://pb.dmcraft.online', data=payload)
print(response)
while str(response) != "<Response [200]>":
response = requests.post('http://pb.dmcraft.online', data=payload)
print("Retrying...")
print(response)
print("Error, retrying...")
sleep(0.1)
print("DONE!")
def linex(y, x1, x2):
@@ -30,29 +40,28 @@ def liney(x, y1, y2):
res.append( [x,i] )
return res
l = [[65, 86, 'red'], [66, 87, 'red'], [66, 86, 'red'], [66, 85, 'red'], [67, 86, 'red'], [89, 97, 'red'], [90, 98, 'red'], [90, 97, 'red'], [90, 96, 'red'], [91, 97, 'red'], [95, 77, 'black'], [96, 78, 'black'], [96, 77, 'black'], [96, 76, 'black'], [97, 77, 'black'], [107, 108, 'blue'], [108, 109, 'blue'], [108, 108, 'blue'], [108, 107, 'blue'], [109, 108, 'blue']]
draw(l)
def fill(xy1, xy2):
res = []
for x in range(xy1[0], xy2[0] + 1):
for y in range(xy1[1], xy2[1] + 1):
res.append( [x, y] )
return res
#draw( liney(300, 300, 500) )
#draw(linex(500, 300, 500))
print(gcolor(0, 1))
draw([[0,1, "red"]])
'''
xs = 180
ys = 180
#S
cords = [ [3+xs,0+ys],[2+xs,0+ys],[1+xs,0+ys],[1+xs,-1+ys],[1+xs,-2+ys],[2+xs,-2+ys],[3+xs,-2+ys],[3+xs,-3+ys],[3+xs,-4+ys],[2+xs,-4+ys],[1+xs,-4+ys] ]
draw(cords)
#A
cords = [ [5+xs,-4+ys],[5+xs,-3+ys],[5+xs,-2+ys],[5+xs,-1+ys],[5+xs,0+ys],[6+xs,0+ys],[7+xs,0+ys],[8+xs,0+ys],[8+xs,-4+ys],[8+xs,-3+ys],[8+xs,-2+ys],[8+xs,-1+ys],[8+xs,0+ys],[5+xs,-2+ys],[6+xs,-2+ys],[7+xs,-2+ys],[8+xs,-2+ys], ]
draw(cords)
#N
cords = [ [10+xs,-4+ys],[10+xs,-3+ys],[10+xs,-2+ys],[10+xs,-1+ys],[10+xs,0+ys],[11+xs,-1+ys],[12+xs,-2+ys],[13+xs,-3+ys],[14+xs,-4+ys],[15+xs,-4+ys],[15+xs,-3+ys],[15+xs,-2+ys],[15+xs,-1+ys],[15+xs,0+ys], ]
draw(cords)
#S
xs = xs + 16
cords = [ [3+xs,0+ys],[2+xs,0+ys],[1+xs,0+ys],[1+xs,-1+ys],[1+xs,-2+ys],[2+xs,-2+ys],[3+xs,-2+ys],[3+xs,-3+ys],[3+xs,-4+ys],[2+xs,-4+ys],[1+xs,-4+ys] ]
draw(cords)
#Russian flag
draw(fill([300,300], [330, 300]))
draw(fill([300,330], [330, 330]))
draw(fill([300,300], [300, 330]))
draw(fill([330,300], [330, 330]))
draw(fill([301,321], [329, 329]), "white")
draw(fill([301,310], [329, 320]), "blue")
draw(fill([301,301], [329, 310]), "red")
'''
+50 -18
View File
@@ -3,9 +3,10 @@ from tkinter import *
####DRAW BLOCK
import requests
from time import sleep
from tqdm import tqdm
def draw(cords):
for i in range(len(cords)):
for i in tqdm(range(len(cords))):
sleep(0.2)
try:
payload = {'x': cords[i][1], 'y': cords[i][0], 'color': cords[i][2]}
@@ -13,12 +14,12 @@ def draw(cords):
payload = {'x': cords[i][1], 'y': cords[i][0], 'color': "b" }
response = requests.post('http://pb.dmcraft.online', data=payload)
print(response)
#print(response)
while str(response) != "<Response [200]>":
response = requests.post('http://pb.dmcraft.online', data=payload)
print("Retrying...")
print(response)
print("Error, retrying...")
#print(response)
print("!!!DONE!!!")
@@ -47,6 +48,13 @@ class PixelArt:
self.export_button = Button(self.button_frame, text="Upload", command=self.upload_image)
self.export_button.pack(side=TOP, padx=5, pady=5)
self.button_frame.pack(side=LEFT, padx=5, pady=5)
self.export_button = Button(self.button_frame, text="Move", command=self.move_image)
self.export_button.pack(side=TOP, padx=5, pady=5)
self.xc = 0
self.yc = 0
self.color_buttons = []
for color in self.colors:
button = Button(self.button_frame, bg=color, width=3, height=1, command=lambda c=color: self.set_color(c))
@@ -55,12 +63,14 @@ class PixelArt:
for i in range(129):
self.canvas.create_line(i*12, 0, i*12, 128*12, fill="white")
self.canvas.create_line(0, i*12, 128*12, i*12, fill="white")
self.canvas.bind("<Button-1>", self.draw_pixel)
#self.canvas.bind("<Button-1>", self.draw_pixel)
self.canvas.bind("<B1-Motion>", self.draw_pixel)
def draw_pixel(self, event):
x = int(event.x / 12)
y = int(event.y / 12)
self.canvas.create_rectangle(x*12, y*12, x*12 + 12, y*12 + 12, fill=self.current_color)
#self.canvas.create_rectangle(x*12, y*12, x*12 + 12, y*12 + 12, fill=self.current_color)
self.canvas.create_rectangle(x * 12, y * 12, x * 12 + 12, y * 12 + 12, fill=self.current_color, outline="")
def set_color(self, color):
self.current_color = color
@@ -70,22 +80,44 @@ class PixelArt:
for item in items:
self.canvas.delete(item)
def move_image(self):
def submit():
self.xc = int(xc_entry.get())
self.yc = int(yc_entry.get())
root.destroy()
return 0
root = Tk()
root.title("Смещение по X и Y")
xc_label = Label(root, text="Смещение Х: ", font=("Arial", 16))
xc_label.pack()
xc_entry = Entry(root, width=20, font=("Arial", 16))
xc_entry.pack()
yc_label = Label(root, text="Смещение Y: ", font=("Arial", 16))
yc_label.pack()
yc_entry = Entry(root, width=20, font=("Arial", 16))
yc_entry.pack()
submit_button = Button(root, text="OK", command=submit)
submit_button.pack()
root.mainloop()
def upload_image(self):
pixel_data = []
for i in range(128):
for j in range(128):
color = self.canvas.itemcget(self.canvas.find_closest(i*12+6, j*12+6), "fill")
if color != "white":
match self.colors.index(color):
case 0:
tc = self.colors.index(color)
if tc == 0:
color = "red"
case 1:
elif tc == 1:
color = "green"
case 2:
elif tc == 2:
color = "blue"
case 3:
elif tc == 3:
color = "black"
pixel_data.append([i, 127-j, color])
pixel_data.append([i+ self.xc, 127-j +self.yc, color])
print("!!!START UPLOAD!!!")
draw(pixel_data)
@@ -95,16 +127,16 @@ class PixelArt:
for j in range(128):
color = self.canvas.itemcget(self.canvas.find_closest(i*12+6, j*12+6), "fill")
if color != "white":
match self.colors.index(color):
case 0:
tc = self.colors.index(color)
if tc == 0:
color = "red"
case 1:
elif tc == 1:
color = "green"
case 2:
elif tc == 2:
color = "blue"
case 3:
elif tc == 3:
color = "black"
pixel_data.append([i, 127-j, color])
pixel_data.append([i+ self.xc, 127-j +self.yc, color])
f = open('out.txt', 'w')
f.write(str(pixel_data))
f.close()
+26 -5
View File
@@ -8,16 +8,37 @@ import time
global LTIME
LTIME = cur_time = time.monotonic()
def kbv(dict_, value):
for i in dict_:
if dict_[i] == value:
return i
class RequestHandler(BaseHTTPRequestHandler):
MATRIX_SIZE = (800, 1024)
COLORS = {
'w': (255, 255, 255),
'b': (0, 0, 0),
'r': (255, 0, 0),
'g': (0, 255, 0),
'white': (255, 255, 255),
'blue': (0, 0, 255),
'red': (255, 0, 0),
'green': (0, 255, 0),
'black': (0, 0, 0)
}
def do_GET(self):
params = parse_qs(self.path[2:])
if 'get_color' in params:
x, y = map(int, params['get_color'][0].split(','))
matrix = self.get_matrix()
color = matrix[x][y]
#Magic~~~
color = tuple(list(map(int, str(color)[1:-1].split())))
color = kbv(self.COLORS, color)
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write(f'{color}'.encode())
else:
self.send_response(200)
self.send_header('Content-type', 'image/png')
self.end_headers()
@@ -32,7 +53,7 @@ class RequestHandler(BaseHTTPRequestHandler):
address = self.client_address[0]
print("IP: ", address)
if cur_time - LTIME <= 0.01:
if cur_time - LTIME <= 0.005:
self.send_error(429, 'Too Many Requests')
self.send_response(429)
return 0
+4
View File
@@ -4,3 +4,7 @@ payload = {'x': 52, 'y': 20, 'color': 'r'}
#response = requests.post('http://pb.dmcraft.online', data=payload)
response = requests.post('http://127.0.0.1:3333', data=payload)
print(response)
#Get color
response = requests.get('http://127.0.0.1:3333/?get_color=52,20')
print(response.text)