Advertisement
Natsukl

gartic phone bot color edition

Dec 30th, 2023 (edited)
2,076
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.90 KB | Source Code | 0 0
  1. # @Scar32 on discord
  2. # DEVIXLER production
  3. # gartic phone bot color
  4. # works with any paint program with a box tool as well *
  5.  
  6. # WIP this is work in progress! *
  7. # this bot won't get pixels from your screen to create a color pallet
  8. # the color pallet for gartic phone is provided and if I find a way to
  9. # do that I will create an update on my YT channel @Scar32
  10.  
  11. import pyautogui
  12. from PIL import Image
  13. import time
  14. import math
  15. import getpixelcolor
  16.  
  17. img = Image.open("your image here.img")
  18. # 0.05 works the best for me
  19. pyautogui.PAUSE = 0.05  # if it is too slow make this number smaller, if it too fast (image not proparly drawing) make the number bigger
  20. pixelsize = 2  # size of the pixels, e.g. 8 would make the pixels 8 times larger for making something like pixle art
  21. skip_white = True  # this makes the program skip drawing the white areas of the image, turn this off if you don't want the white parts to be transperent
  22. width, height = img.size
  23. img = img.convert("RGB")
  24. img = img.load()
  25. dithere = [7, 3, 5, 1]  # adding dithering will make this:P
  26. ditherx = [1, -1, 0, 1]
  27. dithery = [0, 1, 1, 1]  # bot run to slow
  28. pallet = [0, 0, 0, 255, 255, 255, 50, 113, 45, 81, 172, 76, 168, 114, 48, 247, 194, 77, 102, 102, 102, 170, 170, 170,
  29.           141, 26, 17, 235, 51, 42, 140, 28, 77, 235, 54, 141, 23, 83, 198, 94, 199, 250, 140, 69, 32, 239, 127, 64,
  30.           190, 96, 91, 243, 178, 170]
  31. colorStats = []
  32. for i in range(18):
  33.     colorStats.append(0)
  34.  
  35.  
  36. def rgb2hex(r, g, b):
  37.     return '{:02x}{:02x}{:02x}'.format(r, g, b)
  38.  
  39.  
  40. def colordif(r1, g1, b1, r2, g2, b2):
  41.     return abs(r1 - r2) + abs(g1 - g2) + abs(b1 - b2)
  42.  
  43.  
  44. def error(r1, g1, b1, r2, g2, b2):
  45.     return r1 - r2, g1 - g2, b1 - b2
  46.  
  47.  
  48. for x in range(width):
  49.     for y in range(height):
  50.         diftest = []
  51.         for c in range(int(len(pallet) / 3)):
  52.             r, g, b = pallet[c * 3], pallet[c * 3 + 1], pallet[c * 3 + 2]
  53.             r2, g2, b2 = img[x, y]
  54.             diftest.append(colordif(r, g, b, r2, g2, b2))
  55.         i = diftest.index(min(diftest))
  56.         img[x, y] = i
  57.         colorStats[i] += 1
  58. rows = int(input('how many colors are in a row of the grid of colors: '))
  59. columns = int(input('now how many are in the columns: '))
  60. print('put your mouse in the first color of the grid\nthen when the mouse clicks put it in the last')
  61. input('\nhit enter when you are ready')
  62. time.sleep(5)
  63. offsetx, offsety = pyautogui.position() # gets the position of the mouse and clicks
  64. pyautogui.click()
  65. time.sleep(3)
  66. colorx, colory = pyautogui.position() # gets the position of the last color
  67. getpixelcolor.pixel(x=colorx, y=colory) # and does a bit of math
  68. stepx = (colorx - offsetx) / (rows - 1)
  69. stepy = (colory - offsety) / (columns - 1)
  70. for i in range(rows * columns):
  71.     x = int(i / columns)
  72.     y = i % columns
  73.     pyautogui.click(x=(x * stepx) + offsetx, y=(y * stepy) + offsety)
  74.     time.sleep(0.25)
  75. input('ready to draw the image\nhit enter when you are ready\nthen put your mouse over the area you want it pasted')
  76. time.sleep(5)  # waits for you to put your mouse over to the gartic phone window
  77. mousex, mousey = pyautogui.position()
  78. pyautogui.MINIMUM_DURATION = 0.0
  79.  
  80.  
  81. def square(s):
  82.     square = 1
  83.     output = []
  84.     while square < s:
  85.         output.append(square)
  86.         square *= 2
  87.     return output
  88.  
  89.  
  90. xlist = square(width)
  91. ylist = square(height)
  92. for c in range(len(colorStats)):
  93.     c = colorStats.index(max(colorStats))
  94.     x = int(c / columns)
  95.     y = c % columns
  96.     colorStats[c] = 0
  97.     pyautogui.click(x=(x * stepx) + offsetx, y=(y * stepy) + offsety)
  98.     for squarex in xlist.__reversed__():
  99.         for squarey in ylist.__reversed__():
  100.             for y in range(math.floor(height / squarey)):
  101.                 for x in range(math.floor(width / squarex)):
  102.                     containsColor = False
  103.                     containsBannedColor = False
  104.                     for x2 in range(squarex):
  105.                         for y2 in range(squarey):
  106.                             pixel = img[x * squarex + x2, y * squarey + y2]
  107.                             if pixel[0] == c:
  108.                                 containsColor = True
  109.                             if (pixel[0]) == 250:
  110.                                 containsBannedColor = True
  111.                     if containsColor and not containsBannedColor:
  112.                         pyautogui.moveTo(mousex + x * squarex * pixelsize, mousey + y * squarey * pixelsize) # opo
  113.                         pyautogui.mouseDown(button='left')
  114.                         pyautogui.moveRel(squarex * pixelsize, squarey * pixelsize)
  115.                         pyautogui.mouseUp(button='left')
  116.                         for x2 in range(squarex):
  117.                             for y2 in range(squarey):
  118.                                 pixel = img[x * squarex + x2, y * squarey + y2]
  119.                                 if pixel[0] == c:
  120.                                     img[x * squarex + x2, y * squarey + y2] = 250
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement