Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.35 KB | None | 0 0
  1. import pyautogui
  2. import numpy as np
  3. import time
  4. from PIL import Image
  5.  
  6.  
  7. # координаты элементов
  8. chng_color_pos = (1128, 83)
  9. chng_color_ok_pos = (491, 508)
  10. coord_field = (6, 145)
  11. red_pos = (885, 438)
  12. green_pos = (885, 461)
  13. blue_pos = (885, 485)
  14. color_inputs = red_pos, green_pos, blue_pos
  15.  
  16. white_color = [255, 255, 255]
  17.  
  18. # открытие и уменьшение изображения
  19. im = Image.open("./image.bmp")
  20. w, h = pyautogui.size()
  21. im_w, im_h = im.size
  22. im = im.resize((int(im_w/(im_h/50)), 50), Image.CUBIC)
  23.  
  24. # разложение изображения на пиксели и расчет их координат
  25. im_w, im_h = im.size
  26. pixels = []
  27. for i, pixel in enumerate(im.getdata()):
  28.     y, x = i//im_w, i%im_w
  29.     pixels.append([x, y, *pixel])
  30.  
  31.  
  32. # преобразование цветов
  33. def color_transform(pixels: list):
  34.     for i, pixel in enumerate(pixels):
  35.         # округляем до 10
  36.         pixels[i] = pixel[:2] + list(map(lambda x: x-(x%10), pixel[2:]))
  37.     return pixels
  38.  
  39. # сортировка цветов
  40. def sort_pixels(pixels: list):
  41.     return sorted(pixels, key=lambda x: x[2:], reverse=False)
  42.  
  43.  
  44.  
  45. time.sleep(2)
  46.  
  47. min_time_for_sleep = 1000
  48.  
  49. def draw(pixels):
  50.     time_for_sleep = min_time_for_sleep
  51.     number_of_last_color = 0
  52.     last_color = None
  53.     for pixel in pixels:
  54.         x, y, *color = pixel
  55.         if color != white_color:
  56.             number_of_last_color += 1
  57.             if color != last_color:
  58.                 number_of_last_color = 0
  59.                 last_color = color
  60.                 time_for_sleep += 50
  61.                 pyautogui.leftClick(*chng_color_pos,)
  62.                 for color, coord in zip(color, color_inputs):
  63.                     pyautogui.leftClick(*coord, _pause=False)
  64.                     pyautogui.press('del', 3, _pause=False)
  65.                     pyautogui.write(str(color), _pause=False)
  66.                 pyautogui.leftClick(*chng_color_ok_pos, _pause=False)
  67.             pyautogui.leftClick(coord_field[0]+x+(x*7),
  68.                                 coord_field[1]+y+(y*7),
  69.                                 _pause=False)
  70.  
  71.             if color == last_color and time_for_sleep > min_time_for_sleep:
  72.                 time_for_sleep -= number_of_last_color/10
  73.  
  74.             time.sleep(1/time_for_sleep)
  75.  
  76.  
  77. draw(sort_pixels(color_transform(pixels)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement