Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1b415d50c5 | |||
| 4f5e14e131 | |||
| 380930e8e7 | |||
| df06ca94a3 | |||
| f5ed42c5e6 | |||
| 74ad0ad523 | |||
| 16930a2770 | |||
| 3ad7d6f6fc | |||
| 855e80f6e5 | |||
| f87c84db30 | |||
| 10dab6a7f5 | |||
| 864a07cd89 | |||
| 67762fda4a | |||
| c8c6b2f405 | |||
| ae874feb75 | |||
| d3b4728c3c | |||
| 99ec1d099d | |||
| 9a83760295 | |||
| e0995302eb | |||
| 33c335b001 | |||
| 35574ef69f | |||
| 3b72176d9c |
@@ -19,11 +19,13 @@ Super simple, super stupid.
|
|||||||
Вы можете написать свой скрипт на основе post.py или...
|
Вы можете написать свой скрипт на основе post.py или...
|
||||||
1. Скачать bot.py
|
1. Скачать bot.py
|
||||||
2. Запрогроммировать свои инструкции для бота:
|
2. Запрогроммировать свои инструкции для бота:
|
||||||
#### draw([0,1], [0,2]) - Функция для рисования, использует массив списков.
|
#### draw([0,1], [0,2], "blue") - Функция для рисования, использует массив списков.
|
||||||
( Поставить точки в координатах [0,1] и [0,2] формата [x,y] )
|
( Поставить точки в координатах [0,1] и [0,2] формата [x,y] )
|
||||||
#### linex(y, x1, x2) - Функция для создания массива линии по координате Х
|
#### linex(y, x1, x2) - Функция для создания массива линии по координате Х
|
||||||
( Y остаётся таким же, массив идёт из x1 в x2 )
|
( Y остаётся таким же, массив идёт из x1 в x2 )
|
||||||
#### liney(x, y1, y2) - Аналогично.
|
#### liney(x, y1, y2) - Аналогично.
|
||||||
|
#### fill([x1,y1], [x2, y2]) - Генерация массива для заполнения, дальше передавать в draw()
|
||||||
|
#### xc - Смещение по X ; yc - Смещение по Y
|
||||||
## --------------------------------
|
## --------------------------------
|
||||||
|
|
||||||
## Установка своего сервера:
|
## Установка своего сервера:
|
||||||
|
|||||||
@@ -1,21 +1,31 @@
|
|||||||
import requests
|
import requests
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
from tqdm import tqdm
|
||||||
|
|
||||||
def draw(cords):
|
global xc, yc
|
||||||
for i in range(len(cords)):
|
xc = 0 ; yc = 0
|
||||||
sleep(0.2)
|
|
||||||
|
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:
|
try:
|
||||||
payload = {'x': cords[i][1], 'y': cords[i][0], 'color': cords[i][2]}
|
color = cords[i][2]
|
||||||
except:
|
except:
|
||||||
payload = {'x': cords[i][1], 'y': cords[i][0], 'color': "blue" }
|
pass
|
||||||
|
|
||||||
response = requests.post('http://pb.dmcraft.online', data=payload)
|
if str(gcolor(cords[i][1], cords[i][0])) != color:
|
||||||
print(response)
|
payload = {'x': cords[i][1] + yc, 'y': cords[i][0] + xc, 'color': color }
|
||||||
|
|
||||||
while str(response) != "<Response [200]>":
|
|
||||||
response = requests.post('http://pb.dmcraft.online', data=payload)
|
response = requests.post('http://pb.dmcraft.online', data=payload)
|
||||||
print("Retrying...")
|
|
||||||
print(response)
|
while str(response) != "<Response [200]>":
|
||||||
|
response = requests.post('http://pb.dmcraft.online', data=payload)
|
||||||
|
print("Error, retrying...")
|
||||||
|
sleep(0.1)
|
||||||
print("DONE!")
|
print("DONE!")
|
||||||
|
|
||||||
def linex(y, x1, x2):
|
def linex(y, x1, x2):
|
||||||
@@ -30,29 +40,28 @@ def liney(x, y1, y2):
|
|||||||
res.append( [x,i] )
|
res.append( [x,i] )
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def fill(xy1, xy2):
|
||||||
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']]
|
res = []
|
||||||
|
for x in range(xy1[0], xy2[0] + 1):
|
||||||
draw(l)
|
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
|
#Russian flag
|
||||||
ys = 180
|
draw(fill([300,300], [330, 300]))
|
||||||
#S
|
draw(fill([300,330], [330, 330]))
|
||||||
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(fill([300,300], [300, 330]))
|
||||||
draw(cords)
|
draw(fill([330,300], [330, 330]))
|
||||||
#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(fill([301,321], [329, 329]), "white")
|
||||||
draw(cords)
|
draw(fill([301,310], [329, 320]), "blue")
|
||||||
#N
|
draw(fill([301,301], [329, 310]), "red")
|
||||||
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)
|
|
||||||
'''
|
'''
|
||||||
|
|||||||
+58
-26
@@ -3,9 +3,10 @@ from tkinter import *
|
|||||||
####DRAW BLOCK
|
####DRAW BLOCK
|
||||||
import requests
|
import requests
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
from tqdm import tqdm
|
||||||
|
|
||||||
def draw(cords):
|
def draw(cords):
|
||||||
for i in range(len(cords)):
|
for i in tqdm(range(len(cords))):
|
||||||
sleep(0.2)
|
sleep(0.2)
|
||||||
try:
|
try:
|
||||||
payload = {'x': cords[i][1], 'y': cords[i][0], 'color': cords[i][2]}
|
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" }
|
payload = {'x': cords[i][1], 'y': cords[i][0], 'color': "b" }
|
||||||
|
|
||||||
response = requests.post('http://pb.dmcraft.online', data=payload)
|
response = requests.post('http://pb.dmcraft.online', data=payload)
|
||||||
print(response)
|
#print(response)
|
||||||
|
|
||||||
while str(response) != "<Response [200]>":
|
while str(response) != "<Response [200]>":
|
||||||
response = requests.post('http://pb.dmcraft.online', data=payload)
|
response = requests.post('http://pb.dmcraft.online', data=payload)
|
||||||
print("Retrying...")
|
print("Error, retrying...")
|
||||||
print(response)
|
#print(response)
|
||||||
print("!!!DONE!!!")
|
print("!!!DONE!!!")
|
||||||
|
|
||||||
|
|
||||||
@@ -47,6 +48,13 @@ class PixelArt:
|
|||||||
self.export_button = Button(self.button_frame, text="Upload", command=self.upload_image)
|
self.export_button = Button(self.button_frame, text="Upload", command=self.upload_image)
|
||||||
self.export_button.pack(side=TOP, padx=5, pady=5)
|
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 = []
|
self.color_buttons = []
|
||||||
for color in self.colors:
|
for color in self.colors:
|
||||||
button = Button(self.button_frame, bg=color, width=3, height=1, command=lambda c=color: self.set_color(c))
|
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):
|
for i in range(129):
|
||||||
self.canvas.create_line(i*12, 0, i*12, 128*12, fill="white")
|
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.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):
|
def draw_pixel(self, event):
|
||||||
x = int(event.x / 12)
|
x = int(event.x / 12)
|
||||||
y = int(event.y / 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):
|
def set_color(self, color):
|
||||||
self.current_color = color
|
self.current_color = color
|
||||||
@@ -70,22 +80,44 @@ class PixelArt:
|
|||||||
for item in items:
|
for item in items:
|
||||||
self.canvas.delete(item)
|
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):
|
def upload_image(self):
|
||||||
pixel_data = []
|
pixel_data = []
|
||||||
for i in range(128):
|
for i in range(128):
|
||||||
for j in range(128):
|
for j in range(128):
|
||||||
color = self.canvas.itemcget(self.canvas.find_closest(i*12+6, j*12+6), "fill")
|
color = self.canvas.itemcget(self.canvas.find_closest(i*12+6, j*12+6), "fill")
|
||||||
if color != "white":
|
if color != "white":
|
||||||
match self.colors.index(color):
|
tc = self.colors.index(color)
|
||||||
case 0:
|
if tc == 0:
|
||||||
color = "red"
|
color = "red"
|
||||||
case 1:
|
elif tc == 1:
|
||||||
color = "green"
|
color = "green"
|
||||||
case 2:
|
elif tc == 2:
|
||||||
color = "blue"
|
color = "blue"
|
||||||
case 3:
|
elif tc == 3:
|
||||||
color = "black"
|
color = "black"
|
||||||
pixel_data.append([i, 127-j, color])
|
pixel_data.append([i+ self.xc, 127-j +self.yc, color])
|
||||||
print("!!!START UPLOAD!!!")
|
print("!!!START UPLOAD!!!")
|
||||||
draw(pixel_data)
|
draw(pixel_data)
|
||||||
|
|
||||||
@@ -95,16 +127,16 @@ class PixelArt:
|
|||||||
for j in range(128):
|
for j in range(128):
|
||||||
color = self.canvas.itemcget(self.canvas.find_closest(i*12+6, j*12+6), "fill")
|
color = self.canvas.itemcget(self.canvas.find_closest(i*12+6, j*12+6), "fill")
|
||||||
if color != "white":
|
if color != "white":
|
||||||
match self.colors.index(color):
|
tc = self.colors.index(color)
|
||||||
case 0:
|
if tc == 0:
|
||||||
color = "red"
|
color = "red"
|
||||||
case 1:
|
elif tc == 1:
|
||||||
color = "green"
|
color = "green"
|
||||||
case 2:
|
elif tc == 2:
|
||||||
color = "blue"
|
color = "blue"
|
||||||
case 3:
|
elif tc == 3:
|
||||||
color = "black"
|
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 = open('out.txt', 'w')
|
||||||
f.write(str(pixel_data))
|
f.write(str(pixel_data))
|
||||||
f.close()
|
f.close()
|
||||||
|
|||||||
@@ -8,23 +8,44 @@ import time
|
|||||||
global LTIME
|
global LTIME
|
||||||
LTIME = cur_time = time.monotonic()
|
LTIME = cur_time = time.monotonic()
|
||||||
|
|
||||||
|
def kbv(dict_, value):
|
||||||
|
for i in dict_:
|
||||||
|
if dict_[i] == value:
|
||||||
|
return i
|
||||||
|
|
||||||
class RequestHandler(BaseHTTPRequestHandler):
|
class RequestHandler(BaseHTTPRequestHandler):
|
||||||
MATRIX_SIZE = (800, 1024)
|
MATRIX_SIZE = (800, 1024)
|
||||||
COLORS = {
|
COLORS = {
|
||||||
'w': (255, 255, 255),
|
'white': (255, 255, 255),
|
||||||
'b': (0, 0, 0),
|
'blue': (0, 0, 255),
|
||||||
'r': (255, 0, 0),
|
'red': (255, 0, 0),
|
||||||
'g': (0, 255, 0),
|
'green': (0, 255, 0),
|
||||||
|
'black': (0, 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
self.send_response(200)
|
params = parse_qs(self.path[2:])
|
||||||
self.send_header('Content-type', 'image/png')
|
if 'get_color' in params:
|
||||||
self.end_headers()
|
x, y = map(int, params['get_color'][0].split(','))
|
||||||
|
matrix = self.get_matrix()
|
||||||
|
color = matrix[x][y]
|
||||||
|
|
||||||
matrix = self.get_matrix()
|
#Magic~~~
|
||||||
matrix = np.flip(matrix, axis=0)
|
color = tuple(list(map(int, str(color)[1:-1].split())))
|
||||||
self.send_image(matrix)
|
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()
|
||||||
|
|
||||||
|
matrix = self.get_matrix()
|
||||||
|
matrix = np.flip(matrix, axis=0)
|
||||||
|
self.send_image(matrix)
|
||||||
|
|
||||||
def do_POST(self):
|
def do_POST(self):
|
||||||
global LTIME
|
global LTIME
|
||||||
@@ -32,7 +53,7 @@ class RequestHandler(BaseHTTPRequestHandler):
|
|||||||
address = self.client_address[0]
|
address = self.client_address[0]
|
||||||
print("IP: ", address)
|
print("IP: ", address)
|
||||||
|
|
||||||
if cur_time - LTIME <= 0.01:
|
if cur_time - LTIME <= 0.005:
|
||||||
self.send_error(429, 'Too Many Requests')
|
self.send_error(429, 'Too Many Requests')
|
||||||
self.send_response(429)
|
self.send_response(429)
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
@@ -4,3 +4,7 @@ payload = {'x': 52, 'y': 20, 'color': 'r'}
|
|||||||
#response = requests.post('http://pb.dmcraft.online', data=payload)
|
#response = requests.post('http://pb.dmcraft.online', data=payload)
|
||||||
response = requests.post('http://127.0.0.1:3333', data=payload)
|
response = requests.post('http://127.0.0.1:3333', data=payload)
|
||||||
print(response)
|
print(response)
|
||||||
|
|
||||||
|
#Get color
|
||||||
|
response = requests.get('http://127.0.0.1:3333/?get_color=52,20')
|
||||||
|
print(response.text)
|
||||||
|
|||||||
Reference in New Issue
Block a user