parent
d327ae0aa4
commit
9edd68cccc
@ -0,0 +1,23 @@
|
||||
from listwork import *
|
||||
from random import randint as ri
|
||||
|
||||
# pas2( fill(...) ) -> 1/2
|
||||
def pas2(pxls):
|
||||
new_pxls = []
|
||||
|
||||
pas = False
|
||||
for i in pxls:
|
||||
if not pas:
|
||||
new_pxls.append(i)
|
||||
pas = True
|
||||
else:
|
||||
pas = False
|
||||
return new_pxls
|
||||
|
||||
# rand(x1,y1, x2,y2) -> draw() or pas2()
|
||||
def rand(x1,y1, x2,y2):
|
||||
pxls = []
|
||||
for x in range(x1, x2 +1):
|
||||
for y in range(y1, y2 +1):
|
||||
pxls.append([x,y, ri(0,255), ri(0,255), ri(0,255)])
|
||||
return pxls
|
@ -0,0 +1,42 @@
|
||||
import tkinter as tk
|
||||
from time import sleep
|
||||
|
||||
def start_drag(event):
|
||||
global current_coords
|
||||
global dragged_item
|
||||
dragged_item = label
|
||||
current_coords = label.winfo_pointerx(), label.winfo_pointery()
|
||||
|
||||
def stop_drag(event):
|
||||
dragged_item = None
|
||||
|
||||
def drag(event):
|
||||
global current_coords
|
||||
xc, yc = label.winfo_pointerx(), label.winfo_pointery()
|
||||
dx, dy = xc - current_coords[0], yc - current_coords[1]
|
||||
current_coords = xc, yc
|
||||
label.place(x=label.winfo_x() + dx, y=label.winfo_y() + dy)
|
||||
|
||||
def nn(root,im):
|
||||
global label
|
||||
|
||||
image = tk.PhotoImage(file=im) # Use self.image
|
||||
label = tk.Label(root, image=image)
|
||||
label.image = image # Keep a reference to the image
|
||||
label.pack()
|
||||
|
||||
dragged_item = None
|
||||
current_coords = 0, 0
|
||||
|
||||
label.bind('<ButtonPress-1>', start_drag)
|
||||
label.bind('<ButtonRelease-1>', stop_drag)
|
||||
label.bind('<B1-Motion>', drag)
|
||||
# globals().update(locals())
|
||||
|
||||
while True:
|
||||
tk.Misc.lift(label)
|
||||
sleep(0.05)
|
||||
|
||||
print("Image cords: ", label.winfo_x(), 670 - label.winfo_y())
|
||||
#x1, y1 = image.coords(image)
|
||||
# print(f'Image cords: {}')
|
@ -0,0 +1,52 @@
|
||||
from PIL import Image, ImageOps
|
||||
|
||||
# [[0,0, rgb1],... [1,1, rgb2]] -> [[1,1, rgb1],...[0,0, rgb2]]
|
||||
def flip(cords):
|
||||
fliped = []
|
||||
flips = len(cords)//2
|
||||
|
||||
# El from start and el from end
|
||||
fl0 = 0 ; fl1 = len(cords)-1
|
||||
|
||||
for i in range(flips):
|
||||
# Copy element and change cords to cords of end element
|
||||
new_st = list(cords[fl0])
|
||||
new_st[0] = cords[fl1][0]
|
||||
new_st[1] = cords[fl1][1]
|
||||
fliped.append(new_st)
|
||||
|
||||
# Copy and change cords to cords of start element
|
||||
new_end = list(cords[fl1])
|
||||
new_end[0] = cords[fl0][0]
|
||||
new_end[1] = cords[fl0][1]
|
||||
fliped.append(new_end)
|
||||
|
||||
fl0 += 1 ; fl1 -= 1
|
||||
|
||||
return fliped
|
||||
|
||||
# convert("example.png") // png/jpg/gif
|
||||
def convert(filename, move = [0,0]):
|
||||
im = Image.open(filename).convert('RGB')
|
||||
# Fix mirror
|
||||
im = ImageOps.mirror(im)
|
||||
pxls=im.load()
|
||||
w=im.size[0]
|
||||
h=im.size[1]
|
||||
|
||||
ll = []
|
||||
for x in range(w):
|
||||
for y in range(h):
|
||||
# [x,y, [r, g, b]]
|
||||
rgb = pxls[x,y]
|
||||
ll.append( [x,y, rgb[0], rgb[1], rgb[2] ] )
|
||||
|
||||
# Fix flip
|
||||
fliped = flip(ll)
|
||||
|
||||
# Move [x,y] + move
|
||||
moved = []
|
||||
for i in fliped:
|
||||
moved.append([i[0] + move[0], i[1] + move[1], i[2],i[3],i[4]])
|
||||
|
||||
return moved
|
@ -0,0 +1,24 @@
|
||||
def unpack(string):
|
||||
ll = string.split('-_')
|
||||
ll.remove("") # Remove empty line
|
||||
el_col = ll[0].count('-')
|
||||
|
||||
post_ll = []
|
||||
for i in ll:
|
||||
temp = i.split("-")
|
||||
# Multi-add (2, 3 or 5 elements)
|
||||
if el_col == 1:
|
||||
post_ll.append([int(temp[0]), int(temp[1])])
|
||||
elif el_col == 2:
|
||||
post_ll.append([int(temp[0]), int(temp[1]), int(temp[2])])
|
||||
elif el_col == 4:
|
||||
post_ll.append([int(temp[0]), int(temp[1]), int(temp[2]), int(temp[3]), int(temp[4]) ])
|
||||
return post_ll
|
||||
|
||||
def pack(ll):
|
||||
string = ''
|
||||
for el in ll:
|
||||
for i in el:
|
||||
string += str(i) + '-'
|
||||
string += '_'
|
||||
return string
|
Loading…
Reference in new issue