Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # @Scar32 on discord
- # DEVIXLER production
- # gartic phone bot color
- # works with any paint program with a box tool as well *
- # WIP this is work in progress! *
- # this bot won't get pixels from your screen to create a color pallet
- # the color pallet for gartic phone is provided and if I find a way to
- # do that I will create an update on my YT channel @Scar32
- import pyautogui
- from PIL import Image
- import time
- import math
- import getpixelcolor
- img = Image.open("your image here.img")
- # 0.05 works the best for me
- 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
- pixelsize = 2 # size of the pixels, e.g. 8 would make the pixels 8 times larger for making something like pixle art
- 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
- width, height = img.size
- img = img.convert("RGB")
- img = img.load()
- dithere = [7, 3, 5, 1] # adding dithering will make this:P
- ditherx = [1, -1, 0, 1]
- dithery = [0, 1, 1, 1] # bot run to slow
- 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,
- 141, 26, 17, 235, 51, 42, 140, 28, 77, 235, 54, 141, 23, 83, 198, 94, 199, 250, 140, 69, 32, 239, 127, 64,
- 190, 96, 91, 243, 178, 170]
- colorStats = []
- for i in range(18):
- colorStats.append(0)
- def rgb2hex(r, g, b):
- return '{:02x}{:02x}{:02x}'.format(r, g, b)
- def colordif(r1, g1, b1, r2, g2, b2):
- return abs(r1 - r2) + abs(g1 - g2) + abs(b1 - b2)
- def error(r1, g1, b1, r2, g2, b2):
- return r1 - r2, g1 - g2, b1 - b2
- for x in range(width):
- for y in range(height):
- diftest = []
- for c in range(int(len(pallet) / 3)):
- r, g, b = pallet[c * 3], pallet[c * 3 + 1], pallet[c * 3 + 2]
- r2, g2, b2 = img[x, y]
- diftest.append(colordif(r, g, b, r2, g2, b2))
- i = diftest.index(min(diftest))
- img[x, y] = i
- colorStats[i] += 1
- rows = int(input('how many colors are in a row of the grid of colors: '))
- columns = int(input('now how many are in the columns: '))
- print('put your mouse in the first color of the grid\nthen when the mouse clicks put it in the last')
- input('\nhit enter when you are ready')
- time.sleep(5)
- offsetx, offsety = pyautogui.position() # gets the position of the mouse and clicks
- pyautogui.click()
- time.sleep(3)
- colorx, colory = pyautogui.position() # gets the position of the last color
- getpixelcolor.pixel(x=colorx, y=colory) # and does a bit of math
- stepx = (colorx - offsetx) / (rows - 1)
- stepy = (colory - offsety) / (columns - 1)
- for i in range(rows * columns):
- x = int(i / columns)
- y = i % columns
- pyautogui.click(x=(x * stepx) + offsetx, y=(y * stepy) + offsety)
- time.sleep(0.25)
- input('ready to draw the image\nhit enter when you are ready\nthen put your mouse over the area you want it pasted')
- time.sleep(5) # waits for you to put your mouse over to the gartic phone window
- mousex, mousey = pyautogui.position()
- pyautogui.MINIMUM_DURATION = 0.0
- def square(s):
- square = 1
- output = []
- while square < s:
- output.append(square)
- square *= 2
- return output
- xlist = square(width)
- ylist = square(height)
- for c in range(len(colorStats)):
- c = colorStats.index(max(colorStats))
- x = int(c / columns)
- y = c % columns
- colorStats[c] = 0
- pyautogui.click(x=(x * stepx) + offsetx, y=(y * stepy) + offsety)
- for squarex in xlist.__reversed__():
- for squarey in ylist.__reversed__():
- for y in range(math.floor(height / squarey)):
- for x in range(math.floor(width / squarex)):
- containsColor = False
- containsBannedColor = False
- for x2 in range(squarex):
- for y2 in range(squarey):
- pixel = img[x * squarex + x2, y * squarey + y2]
- if pixel[0] == c:
- containsColor = True
- if (pixel[0]) == 250:
- containsBannedColor = True
- if containsColor and not containsBannedColor:
- pyautogui.moveTo(mousex + x * squarex * pixelsize, mousey + y * squarey * pixelsize) # opo
- pyautogui.mouseDown(button='left')
- pyautogui.moveRel(squarex * pixelsize, squarey * pixelsize)
- pyautogui.mouseUp(button='left')
- for x2 in range(squarex):
- for y2 in range(squarey):
- pixel = img[x * squarex + x2, y * squarey + y2]
- if pixel[0] == c:
- img[x * squarex + x2, y * squarey + y2] = 250
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement