Update: add uploader, add cleaner, add black color and update color code
This commit is contained in:
parent
01f0ce97c7
commit
7b45803a2c
70
im_create.py
70
im_create.py
@ -1,5 +1,29 @@
|
||||
from tkinter import *
|
||||
|
||||
####DRAW BLOCK
|
||||
import requests
|
||||
from time import sleep
|
||||
|
||||
def draw(cords):
|
||||
for i in range(len(cords)):
|
||||
sleep(0.2)
|
||||
try:
|
||||
payload = {'x': cords[i][1], 'y': cords[i][0], 'color': cords[i][2]}
|
||||
except:
|
||||
payload = {'x': cords[i][1], 'y': cords[i][0], 'color': "b" }
|
||||
|
||||
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("!!!DONE!!!")
|
||||
|
||||
|
||||
|
||||
|
||||
class PixelArt:
|
||||
|
||||
def __init__(self, master):
|
||||
@ -7,12 +31,22 @@ class PixelArt:
|
||||
self.master.title("Pixel Art")
|
||||
self.canvas = Canvas(self.master, width=128*12, height=128*12, bg="white")
|
||||
self.canvas.pack(side=LEFT, padx=5, pady=5)
|
||||
self.colors = ["red", "green", "blue", "white"]
|
||||
self.colors = ["red", "green", "blue", "white","black"]
|
||||
self.current_color = "red"
|
||||
self.button_frame = Frame(self.master)
|
||||
|
||||
self.button_frame.pack(side=LEFT, padx=5, pady=5)
|
||||
self.export_button = Button(self.button_frame, text="Export", command=self.export_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="Clean", command=self.clean_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="Upload", command=self.upload_image)
|
||||
self.export_button.pack(side=TOP, padx=5, pady=5)
|
||||
|
||||
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))
|
||||
@ -31,6 +65,30 @@ class PixelArt:
|
||||
def set_color(self, color):
|
||||
self.current_color = color
|
||||
|
||||
def clean_image(self):
|
||||
items = self.canvas.find_all()
|
||||
for item in items:
|
||||
self.canvas.delete(item)
|
||||
|
||||
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:
|
||||
color = "red"
|
||||
case 1:
|
||||
color = "green"
|
||||
case 2:
|
||||
color = "blue"
|
||||
case 3:
|
||||
color = "black"
|
||||
pixel_data.append([i, 127-j, color])
|
||||
print("!!!START UPLOAD!!!")
|
||||
draw(pixel_data)
|
||||
|
||||
def export_image(self):
|
||||
pixel_data = []
|
||||
for i in range(128):
|
||||
@ -39,12 +97,14 @@ class PixelArt:
|
||||
if color != "white":
|
||||
match self.colors.index(color):
|
||||
case 0:
|
||||
color = "r"
|
||||
color = "red"
|
||||
case 1:
|
||||
color = "g"
|
||||
color = "green"
|
||||
case 2:
|
||||
color = "b"
|
||||
pixel_data.append([i, j, color])
|
||||
color = "blue"
|
||||
case 3:
|
||||
color = "black"
|
||||
pixel_data.append([i, 127-j, color])
|
||||
f = open('out.txt', 'w')
|
||||
f.write(str(pixel_data))
|
||||
f.close()
|
||||
|
Loading…
Reference in New Issue
Block a user