Advertisement
Boe6

colorthis.space bot

Apr 8th, 2017
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.91 KB | None | 0 0
  1. # Requirements:
  2. # 'pip install selenium', run from command line (requires pip, Google how to get it if running pip doesn't recognise as a command)
  3. # Google Chrome Webdriver, @ https://sites.google.com/a/chromium.org/chromedriver/downloads
  4. #
  5. # Helpful omstall guide: https://www.youtube.com/watch?v=8iAqUVvytJk
  6.  
  7. import time
  8. from selenium import webdriver
  9. from time import sleep
  10.  
  11. driver = webdriver.Chrome('PATH TO DRIVER.EXE')  # Optional argument, if not specified will search path.
  12. driver.get('http://colorthis.space/');
  13. time.sleep(3) # Let the user actually see something!
  14.  
  15. hex_char = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"]
  16.  
  17. colors = [
  18.             [255, 255, 255, 255],
  19.             [228, 228, 228, 255],
  20.             [136, 136, 136, 255],
  21.             [34, 34, 34, 255],
  22.             [255, 167, 209, 255],
  23.             [229, 0, 0, 255],
  24.             [229, 149, 0, 255],
  25.             [160, 106, 66, 255],
  26.             [229, 217, 0, 255],
  27.             [148, 224, 68, 255],
  28.             [2, 190, 1, 255],
  29.             [0, 211, 221, 255],
  30.             [0, 131, 199, 255],
  31.             [0, 0, 234, 255],
  32.             [207, 110, 228, 255],
  33.             [130, 0, 128, 255]
  34.             ]
  35.  
  36. img1 = [
  37.         '3333333333333333333333333333333333333333333333333333333333333333333333333',
  38.         '3666666666666666666666666666666666666666666666666666666666666666666666663',
  39.         '3633663633366336333633663366666633663366366666666666663633363636636666663',
  40.         '3636363636663666363636363636666366636666366363663636333663663636333633663',
  41.         '3636363666363666363633663636336363636363663636363636363663663336636636363',
  42.         '3633663633366336333636363366336633663363663636366366333633666636636636363',
  43.         '3666666666666666666666666666666666666666666666666666666666666666666666663',
  44.         '3333333333333333333333333333333333333333333333333333333333333333333333333',
  45.         278,83
  46.         ]
  47. img2 = [
  48.         '3666666666666666666666666666666666666666666666666666666666666666666666663',
  49.         '3666666666663666666363336363663663666363663636366366333633366666666666663',
  50.         '3666666666636636663663666363636363636363363636363636636636666666666666663',
  51.         '3666666666636633663663336333633363636363633633363336636633366666666666663',
  52.         '#36666666636663663666663636363636363636363363636363663663666666666666663#',
  53.         '##366666663666366366633363636363663636636636363636366366333666666666663##',
  54.         '###3666666666666666666666666666666666666666666666666666666666666666663###',
  55.         '####33333333333333333333333333333333333333333333333333333333333333333####',
  56.         278,91
  57.         ]
  58. img3 = [
  59.         "3333333333333333333333333333333333",
  60.         "3cccccccc333333333332ccccccccc2123",
  61.         "3cccccc3333333333333332cccccccc123",
  62.         "3ccccc33333333333333333cccccccc223",
  63.         "3cccc3333337773337733333cccccccc23",
  64.         "3cccc33333766666667733332ccccccc23",
  65.         "3cccc33337666666666773333ccccccc23",
  66.         "3cccc33377666666666677333ccccccc23",
  67.         "3cccc333766666666666673332cccccc23",
  68.         "3cccc337766666666666673332cccccc23",
  69.         "3ccccc376666666666666673332ccccc23",
  70.         "3ccccc373333366666333337332ccccc23",
  71.         "3ccccc737777766466667777337ccccc23",
  72.         "3cccc7777733366446633777376ccccc23",
  73.         "3ccccc677766666447666677766ccccc23",
  74.         "3ccccc666666664447776677766ccccc23",
  75.         "3ccccc766666644447776667772ccccc23",
  76.         "3ccccc366666664447776667762cccccc3",
  77.         "3ccccc76666666747777666762ccccccc3",
  78.         "3ccccc27666666677777767722cccccc13",
  79.         "3ccccc2766667666777776676ccccccc13",
  80.         "3cccccc766676666777766667ccccccc13",
  81.         "3cccccc376666667776666667ccccccc13",
  82.         "3cccccc3776666666666666672cccccc23",
  83.         "3cccccc2377666666666666772cccccc13",
  84.         "3ccccccc36776666666666762ccccccc13",
  85.         "3ccccccc26674664666677662ccccccc13",
  86.         "3cccc3c276647747777766662ccccccc13",
  87.         "3333333676644644666666662ccc32cc13",
  88.         "3333336666644444666666666c33333313",
  89.         "3333337676444444466666666333333313",
  90.         "33333333334e04e0466666333333333313",
  91.         "3222222233444444411111111122222223",
  92.         298,50
  93.         ]
  94. img4 = [
  95.         "####3333333333333333",
  96.         "###36666666666666666",
  97.         "##366666633366666666",
  98.         "#3666666636666666666",
  99.         "36666666633366666666",
  100.         "36666666666366666666",
  101.         "36666666633366666666",
  102.         "36666666666666666666",
  103.         "36666666636366666666",
  104.         "36666666636366666666",
  105.         "36666666633366666666",
  106.         "36666666636366666666",
  107.         "36666666636366666666",
  108.         "36666666666666666666",
  109.         "36666666663666666666",
  110.         "36666666636366666666",
  111.         "36666666633366666666",
  112.         "36666666636366666666",
  113.         "36666666636366666666",
  114.         "36666666666666666666",
  115.         "36666666366636666666",
  116.         "36666666363636666666",
  117.         "36666666363636666666",
  118.         "36666666363636666666",
  119.         "36666666636366666666",
  120.         "36666666666666666666",
  121.         "36666666366636666666",
  122.         "36666666336636666666",
  123.         "36666666363636666666",
  124.         "36666666366336666666",
  125.         "36666666366636666666",
  126.         "36666666666666666666",
  127.         "36666666666666666666",
  128.         278,50
  129.         ]
  130. img5 = [
  131.         "333333333333333####",
  132.         "6666666666666663###",
  133.         "66666666666666663##",
  134.         "666666666666666663#",
  135.         "6666666666666666663",
  136.         "6666666666666666663",
  137.         "6666666363666666663",
  138.         "6666666363666666663",
  139.         "6666666333666666663",
  140.         "6666666363666666663",
  141.         "6666666363666666663",
  142.         "6666666666666666663",
  143.         "6666666636666666663",
  144.         "6666666363666666663",
  145.         "6666666333666666663",
  146.         "6666666363666666663",
  147.         "6666666363666666663",
  148.         "6666666666666666663",
  149.         "6666666333666666663",
  150.         "6666666636666666663",
  151.         "6666666636666666663",
  152.         "6666666636666666663",
  153.         "6666666636666666663",
  154.         "6666666666666666663",
  155.         "6666666333666666663",
  156.         "6666666366666666663",
  157.         "6666666333666666663",
  158.         "6666666366666666663",
  159.         "6666666333666666663",
  160.         "6666666666666666663",
  161.         "6666666666666666663",
  162.         "6666666666666666663",
  163.         "6666666666666666663",
  164.         332,50
  165.         ]
  166.  
  167. imageMatrixs = [img1,img2,img3,img4,img5]
  168.  
  169. imageColorsGrouped = []
  170. imageColorsIndex = []
  171. imageColorsHex = ''
  172. imageFormatted = []
  173.  
  174. def placenext(looking=False):
  175.     if driver.execute_script('return notified'):
  176.         looking = True
  177.         for matrix in imageMatrixs:
  178.            
  179.             imageCalled = driver.execute_script('return ctx.getImageData(' + str(matrix[-2]) + ',' + str(matrix[-1]) + ',' + str(len(matrix[0])) + ',' + str(len(matrix)-2) + ').data')
  180.            
  181.             imageColorsGrouped = [imageCalled[i:i+4] for i in range(0, len(imageCalled), 4)]
  182.            
  183.             imageColorsIndex = []
  184.             for cArray in imageColorsGrouped:
  185.                 imageColorsIndex.append(colors.index(cArray))
  186.            
  187.             imageColorsHex = ''
  188.             for cIndex in imageColorsIndex:
  189.                 imageColorsHex += hex_char[cIndex]
  190.            
  191.             height = len(matrix) - 2
  192.            
  193.             imageFormat = []
  194.             imageWidth = (len(imageColorsHex)/(height))
  195.             for i in range(height):
  196.                 imageFormat.append(imageColorsHex[(i*imageWidth):((i+1)*imageWidth)])
  197.            
  198.             if looking == True:
  199.                 for x in range(len(matrix[0])):
  200.                     if looking == True:
  201.                         for y in range(len(matrix)-2):
  202.                             if looking == True and matrix[y][x] != '#':
  203.                                 selectY = ( y + matrix[-1] )
  204.                                 selectX = ( x + matrix[-2] )
  205.                                
  206.                                 try:
  207.                                     if int(hex_char.index(imageFormat[y][x])) == hex_char.index(matrix[y][x]):
  208.                                         pass
  209.                                     elif looking == True:
  210.                                         currC = str(hex_char.index(matrix[y][x]))
  211.                                         driver.execute_script("tryColorPixel(" + str(selectX) + "," + str(selectY) + "," + str(currC) + ")")
  212.                                         print('Coloring:', selectX, selectY, currC)
  213.                                         looking = False
  214.                                     else:
  215.                                         pass
  216.                                 except IndexError:
  217.                                     print("Index Error")
  218.  
  219. def run():
  220.     counter = 0
  221.     while True:
  222.         if counter == 10:
  223.             counter = 0
  224.             time.sleep(0.4)
  225.             placenext()
  226.         else:
  227.             counter += 1
  228.         time.sleep(0.7)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement