-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathim_create.py
147 lines (123 loc) · 5.29 KB
/
im_create.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
from tkinter import *
####DRAW BLOCK
import requests
from time import sleep
from tqdm import tqdm
def draw(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]}
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("Error, retrying...")
#print(response)
print("!!!DONE!!!")
class PixelArt:
def __init__(self, master):
self.master = master
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","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.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))
button.pack(side=TOP, padx=5, pady=5)
self.color_buttons.append(button)
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("<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, outline="")
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 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":
tc = self.colors.index(color)
if tc == 0:
color = "red"
elif tc == 1:
color = "green"
elif tc == 2:
color = "blue"
elif tc == 3:
color = "black"
pixel_data.append([i+ self.xc, 127-j +self.yc, color])
print("!!!START UPLOAD!!!")
draw(pixel_data)
def export_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":
tc = self.colors.index(color)
if tc == 0:
color = "red"
elif tc == 1:
color = "green"
elif tc == 2:
color = "blue"
elif tc == 3:
color = "black"
pixel_data.append([i+ self.xc, 127-j +self.yc, color])
f = open('out.txt', 'w')
f.write(str(pixel_data))
f.close()
if __name__ == "__main__":
root = Tk()
pixel_art = PixelArt(root)
root.mainloop()