Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pyautogui
- import numpy as np
- import time
- from PIL import Image
- # координаты элементов
- chng_color_pos = (1128, 83)
- chng_color_ok_pos = (491, 508)
- coord_field = (6, 145)
- red_pos = (885, 438)
- green_pos = (885, 461)
- blue_pos = (885, 485)
- color_inputs = red_pos, green_pos, blue_pos
- white_color = [255, 255, 255]
- # открытие и уменьшение изображения
- im = Image.open("./image.bmp")
- w, h = pyautogui.size()
- im_w, im_h = im.size
- im = im.resize((int(im_w/(im_h/50)), 50), Image.CUBIC)
- # разложение изображения на пиксели и расчет их координат
- im_w, im_h = im.size
- pixels = []
- for i, pixel in enumerate(im.getdata()):
- y, x = i//im_w, i%im_w
- pixels.append([x, y, *pixel])
- # преобразование цветов
- def color_transform(pixels: list):
- for i, pixel in enumerate(pixels):
- # округляем до 10
- pixels[i] = pixel[:2] + list(map(lambda x: x-(x%10), pixel[2:]))
- return pixels
- # сортировка цветов
- def sort_pixels(pixels: list):
- return sorted(pixels, key=lambda x: x[2:], reverse=False)
- time.sleep(2)
- min_time_for_sleep = 1000
- def draw(pixels):
- time_for_sleep = min_time_for_sleep
- number_of_last_color = 0
- last_color = None
- for pixel in pixels:
- x, y, *color = pixel
- if color != white_color:
- number_of_last_color += 1
- if color != last_color:
- number_of_last_color = 0
- last_color = color
- time_for_sleep += 50
- pyautogui.leftClick(*chng_color_pos,)
- for color, coord in zip(color, color_inputs):
- pyautogui.leftClick(*coord, _pause=False)
- pyautogui.press('del', 3, _pause=False)
- pyautogui.write(str(color), _pause=False)
- pyautogui.leftClick(*chng_color_ok_pos, _pause=False)
- pyautogui.leftClick(coord_field[0]+x+(x*7),
- coord_field[1]+y+(y*7),
- _pause=False)
- if color == last_color and time_for_sleep > min_time_for_sleep:
- time_for_sleep -= number_of_last_color/10
- time.sleep(1/time_for_sleep)
- draw(sort_pixels(color_transform(pixels)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement