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 или...
|
||||
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
|
||||
## --------------------------------
|
||||
|
||||
## Установка своего сервера:
|
||||
|
||||
@@ -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
@@ -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()
|
||||
|
||||
@@ -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,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)
|
||||
|
||||
Reference in New Issue
Block a user