Skip to content

Instantly share code, notes, and snippets.

@lancepioch
Created March 24, 2020 03:11
Show Gist options
  • Save lancepioch/ec8420bbd26710ee18db1b303f806c5b to your computer and use it in GitHub Desktop.
Save lancepioch/ec8420bbd26710ee18db1b303f806c5b to your computer and use it in GitHub Desktop.
from PIL import Image
from icrawler.builtin import BingImageCrawler
import pygame
import os
def choose(keyword):
for num in range(1, 11):
path = "imgs/" + str(num).zfill(6) + ".jpg"
try:
os.remove(path)
except FileNotFoundError:
pass
display = pygame.display.set_mode((640, 480))
content = pygame.Surface((640, 480))
pygame.display.set_caption("Choose Image")
images = []
download(keyword)
for num in range(1, 11):
path = "imgs/" + str(num).zfill(6) + ".jpg"
images.append(pygame.image.load(path))
pointer = 0
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
if pointer > 0:
pointer -= 1
elif event.key == pygame.K_RIGHT:
if pointer < len(images)-1:
pointer += 1
elif event.key == pygame.K_RETURN:
running = False
content.fill((0, 0, 0))
y = content.get_height()
x = int(y * (images[pointer].get_width() / images[pointer].get_height()))
pygame.display.set_mode((x, y))
content = pygame.Surface((x, y))
content.blit(pygame.transform.scale(images[pointer], (x, y)), (0, 0))
display.blit(content, (0, 0))
pygame.display.flip()
pygame.quit()
Image.open("imgs/"+str(pointer+1).zfill(6)+".jpg").save("imgs/img.bmp")
return "imgs/img.bmp"
def download(keyword):
fd = dict(color="white",
size="medium",
layout="tall")
bing_crawler = BingImageCrawler(
parser_threads=5, downloader_threads=5,
storage={'root_dir': 'imgs'})
bing_crawler.session.verify = False
bing_crawler.crawl(keyword=keyword, max_num=10,
min_size=(10, 10), max_size=None,
filters=fd)
import pygame
import skribbl as sk
import download
auto = False
def closest_color(color, palette):
r1, g1, b1 = color
closest_dis = 10000
cc = 0, 0, 0
for r2, g2, b2 in palette:
dis = ((r1 - r2) ** 2 + (g1 - g2) ** 2 + (b1 - b2) ** 2) ** 0.5
if dis < closest_dis:
closest_dis = dis
cc = r2, g2, b2
return cc
def convert(pic):
x_max, y_max = pic.get_size()
pixel = []
for y in range(y_max):
pixel.append([])
for x in range(x_max):
pixel[y].append(list(pic.get_at((x, y))[:3]))
for y in range(y_max):
for x in range(x_max):
oldpixel = pixel[y][x]
newpixel = closest_color(pixel[y][x], sk.colors)
pixel[y][x] = list(newpixel)
for i in (0, 1, 2):
quant_error = oldpixel[i] - newpixel[i]
if x != x_max - 1:
pixel[y][x + 1][i] += quant_error * 7 / 16
if y != y_max - 1 and x:
pixel[y + 1][x - 1][i] += quant_error * 3 / 16
if y != y_max - 1:
pixel[y + 1][x][i] += quant_error * 5 / 16
if y != y_max - 1 and x != x_max - 1:
pixel[y + 1][x + 1][i] += quant_error * 1 / 16
for x in range(x_max):
for y in range(y_max):
# print(pixel[y][x])
pic.set_at((x, y), pixel[y][x] + [255])
def gui(PATH):
pygame.init()
image = pygame.image.load(PATH)
height = 480
SIZE = int(height * (image.get_width() /image.get_height())), height
display = pygame.display.set_mode(SIZE)
content = pygame.Surface(SIZE)
pygame.display.set_caption("Skribbl Bot")
scale = auto
dither = False
draw = False
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN or (scale+dither+draw):
try:
event.key
except AttributeError:
event.key = 0
if event.key == ord('c') or dither:
pygame.display.set_caption("Dither...")
dither = False
convert(image)
if auto:
draw = True
elif event.key == ord('s') or scale:
pygame.display.set_caption("Scale...")
scale = False
if image.get_width() > image.get_height():
width = sk.canvas[1][0] // sk.brush
height = int(width * (image.get_height() / image.get_width()))
else:
height = sk.canvas[1][1] // sk.brush
width = int(height * (image.get_width() / image.get_height()))
image = pygame.transform.scale(image, (int(width), int(height)))
if auto:
dither = True
elif event.key == ord('d') or draw:
pygame.display.set_caption("Drawing...")
draw = False
x_max, y_max = image.get_size()
pixel = []
for y in range(y_max):
pixel.append([])
for x in range(x_max):
pixel[y].append(image.get_at((x, y))[:3])
sk.draw(pixel)
pygame.display.set_caption("Done")
elif event.key == ord('q'):
running = False
content.fill((0, 0, 0))
content.blit(pygame.transform.scale(image, display.get_size()), (0, 0))
display.blit(content, (0, 0))
pygame.display.flip()
pygame.quit()
def main():
keyword = input("Word: ")
path = download.choose(keyword)
gui(path)
main()
if __name__ == "__main__":
print("Skribbl.io bot by hyred-")
main()
import ctypes
from time import sleep
brush = 3
canvas = (483, 260), (814, 600)
MODE = 1
if MODE == 1:
def draw(img):
click(1030, 900)
for current_color in colors:
if current_color == (255, 255, 255):
continue
change_color(current_color)
for y, ly in enumerate(img):
last_color = None
for x, pixel_color in enumerate(ly):
pos = (x*brush+brush/2+canvas[0][0],
y*brush+brush/2+canvas[0][1])
if pixel_color == current_color:
if last_color != pixel_color:
ctypes.windll.user32.mouse_event(1 + 0x8000,
int(65535 * pos[0] / ctypes.windll.user32.GetSystemMetrics(0) + 1),
int(65535 * pos[1] / ctypes.windll.user32.GetSystemMetrics(1) + 1), 0, 0)
ctypes.windll.user32.mouse_event(2, 0, 0, 0, 0)
elif last_color == pixel_color:
ctypes.windll.user32.mouse_event(1 + 0x8000,
int(65535 * pos[0] / ctypes.windll.user32.GetSystemMetrics(0) + 1),
int(65535 * pos[1] / ctypes.windll.user32.GetSystemMetrics(1) + 1), 0, 0)
elif last_color == current_color:
ctypes.windll.user32.mouse_event(4, 0, 0, 0, 0)
sleep(.0001)
last_color = pixel_color
ctypes.windll.user32.mouse_event(4, 0, 0, 0, 0)
elif MODE == 0:
def draw(img):
click(1030, 900)
for y, ly in enumerate(img):
for x, pixel_color in enumerate(ly):
if pixel_color == (255, 255, 255):
continue
change_color(pixel_color)
click(x * brush + brush / 2 + canvas[0][0],
y * brush + brush / 2 + canvas[0][1])
sleep(.0001)
def change_color(color):
i = colors.index(color)
if i <= 10:
x = i*24 + 590
y = 890
else:
x = (i-11)*24 + 590
y = 920
click(x, y)
def cahnge_brushsize(size):
pass
def click(x, y, t=.001):
ctypes.windll.user32.mouse_event(1 + 0x8000,
int(65535 * x / ctypes.windll.user32.GetSystemMetrics(0) + 1),
int(65535 * y / ctypes.windll.user32.GetSystemMetrics(1) + 1), 0, 0)
ctypes.windll.user32.mouse_event(2, 0, 0, 0, 0)
ctypes.windll.user32.mouse_event(4, 0, 0, 0, 0)
sleep(t)
colors = ((255, 255, 255), (193, 193, 193), (239, 19, 11),
(255, 113, 0), (255, 228, 0), (0, 204, 0),
(0, 178, 255), (35, 31, 211), (163, 0, 186),
(211, 124, 170), (160, 82, 42),
(0, 0, 0), (76, 76, 76), (116, 11, 7),
(194, 56, 0), (232, 162, 0), (0, 85, 16),
(0, 86, 158), (14, 8, 101), (85, 0, 105),
(167, 85, 116), (99, 48, 13))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment