def apply(self): print(I18n.get('# From left to right, from top to bottom,')) near_color = 0 for y in xrange(self.bot.image.height): for x in xrange(self.bot.image.width): color = EnumColor.rgb(self.bot.image.pix[x, y]) old_color = self.bot.canvas.get_color(self.bot.start_x + x, self.bot.start_y + y) if color != near_color and old_color != color and not color in self.colors_ignored and old_color not in self.colors_not_overwrite: self.bot.paint(self.bot.start_x + x, self.bot.start_y + y, color) near_color = color near_color = 0 print(I18n.get('# From right to left, from top to bottom,')) near_color = 0 for y in xrange(self.bot.image.height): for x in reversed(xrange(self.bot.image.width)): color = EnumColor.rgb(self.bot.image.pix[x, y]) old_color = self.bot.canvas.get_color(self.bot.start_x + x, self.bot.start_y + y) if color != near_color and old_color != color and not color in self.colors_ignored and old_color not in self.colors_not_overwrite: self.bot.paint(self.bot.start_x + x, self.bot.start_y + y, color) near_color = color near_color = 0 print(I18n.get('# From top to bottom, from left to right,')) near_color = 0 for x in xrange(self.bot.image.width): for y in xrange(self.bot.image.height): color = EnumColor.rgb(self.bot.image.pix[x, y]) old_color = self.bot.canvas.get_color(self.bot.start_x + x, self.bot.start_y + y) if color != near_color and old_color != color and not color in self.colors_ignored and old_color not in self.colors_not_overwrite: self.bot.paint(self.bot.start_x + x, self.bot.start_y + y, color) near_color = color near_color = 0 print(I18n.get('# From bottom to top, from left to right,')) near_color = 0 for x in xrange(self.bot.image.width): for y in reversed(xrange(self.bot.image.height)): color = EnumColor.rgb(self.bot.image.pix[x, y]) old_color = self.bot.canvas.get_color(self.bot.start_x + x, self.bot.start_y + y) if color != near_color and old_color != color and not color in self.colors_ignored and old_color not in self.colors_not_overwrite: self.bot.paint(self.bot.start_x + x, self.bot.start_y + y, color) near_color = color near_color = 0
def paint(self, x, y, color): response = self.pixelio.send_pixel(x, y, color) while not response['success']: print(I18n.get('try_again')) self.wait_time(response) self.pixelio.send_pixel(x, y, color) self.canvas.update(x, y, color) print(I18n.get('You painted %s in the %s,%s') % (I18n.get(str(color.name)), str(x), str(y))) self.wait_time(response)
def wait_time(self, data={'waitSeconds': None}): if data['waitSeconds'] is not None: wait = data['waitSeconds'] + random.randint(0, 5) print(I18n.get('Waiting %s seconds') % str(wait)) max_length = int(wait) at_length = max_length empty = "-" used = "+" bar = empty * max_length for i in range(0, max_length): at_length -= 1 #setting empty and full spots bar = used * i bar = bar + empty * at_length #\r is carriage return(sets cursor position in terminal to start of line) #\0 character escape sys.stdout.write("[{}]\0\r".format(bar)) sys.stdout.flush() #do your stuff here instead of time.sleep time.sleep(1) sys.stdout.write("\n") sys.stdout.flush()
def load_image(self, file): tmb_full_path = os.getcwd() + '/img/.cache/' + self.checksum + '.png' if (os.path.isfile(tmb_full_path)): print(I18n.get('Load cached image')) return pillow.open(tmb_full_path).convert('RGB') print( I18n.get('generating converted image here : %s') % str(tmb_full_path)) new_image = self.convert_pixels(pillow.open(file).convert('RGB')) self.save_image(new_image, tmb_full_path) print(I18n.get('Saved image cache file, Loading Now...')) return pillow.open(tmb_full_path).convert('RGB')
def create_QR_image(text, scale): full_QR_path = os.getcwd() + '/img/QRcode.png' url = pyqrcode.create(text) url.png(full_QR_path, scale) print( I18n.get('Create QR Code succes in here: %s') % str(full_QR_path)) print(url.text())
def build(strategy, bot, colors_ignored, colors_not_overwrite): if strategy == 'randomize': return Randomize(bot, colors_ignored, colors_not_overwrite) if strategy == 'linear': return Linear(bot, colors_ignored, colors_not_overwrite) if strategy == 'qf': return QuickFill(bot, colors_ignored, colors_not_overwrite) if strategy == 'status': return Status(bot, colors_ignored, colors_not_overwrite) if strategy == 'sketch': return Sketch(bot, colors_ignored, colors_not_overwrite) if strategy == 'tlc': return TopLeftCorner(bot, colors_ignored, colors_not_overwrite) if strategy == 'trc': return TopRightCorner(bot, colors_ignored, colors_not_overwrite) if strategy == 'blc': return BottomLeftCorner(bot, colors_ignored, colors_not_overwrite) if strategy == 'brc': return BottomRightCorner(bot, colors_ignored, colors_not_overwrite) if strategy == 'cnb': return CentreNorthBoundary(bot, colors_ignored, colors_not_overwrite) if strategy == 'csb': return CentreSouthBoundary(bot, colors_ignored, colors_not_overwrite) if strategy == 'cwb': return CentreWestBoundary(bot, colors_ignored, colors_not_overwrite) if strategy == 'ceb': return CentreEastBoundary(bot, colors_ignored, colors_not_overwrite) if strategy == 'cpd': return CentrePointDomain(bot, colors_ignored, colors_not_overwrite) if strategy == 'detect': return DetectMinTime(bot, colors_ignored, colors_not_overwrite) print( I18n.get('not fonud strategy %s auto selected randomize') % str(strategy)) return Randomize(bot, colors_ignored, colors_not_overwrite) # Default strategy
def on_message(ws, message): if unpack_from('B', message, 0)[0] == 193: x = unpack_from('!h', message, 1)[0] y = unpack_from('!h', message, 3)[0] a = unpack_from('!H', message, 5)[0] number = (65520 & a) >> 4 x = int(x * 64 + ((number % 64 + 64) % 64)) y = int(y * 64 + math.floor(number / 64)) color = EnumColor.index(15 & a) try: canvas.matrix[x][y] = color if (x in xrange(axis['start_x'], axis['end_x'] + 1) and y in xrange(axis['start_y'], axis['end_y'])) or log_all_info: print( I18n.get('Somebody updated %s,%s with %s color') % (str(x), str(y), I18n.get(color.name))) except Exception as e: pass
def send_pixel(self, x, y, color): payload = '{"x":%s,"y":%s,"%s":%s,"color":%s,"fingerprint":"%s","token":null}' % ( x, y, self.duck, x + y + 2, color.index, self.fingerprint) response = self.post(PixelCanvasIO.URL + 'api/pixel', payload) if response.status_code == 403: raise Exception(I18n.get('Oh no, you are using a proxy')) if response.status_code == 422: raise Exception(I18n.get('refresh_token')) if response.status_code == 429: raise Exception(I18n.get('Rate_limit_exceeded')) try: return response.json() except Exception as e: raise Exception( I18n.get('only_time') + str(response.text) + '-' + str(response.status_code))
def rgb(rgb, silent=False, sensitive=1, brightness=0): for color in EnumColor.ENUM: if rgb == color.rgb: return color #if that colors not in standart colors list diff_min = [ (255, 255, 255), 1038366 ] # sqrt(255*255 + 255*255 + 255*255) = 441.67295593 --> Default white for color in EnumColor.ENUM: #formula that sqrt( (x1 - x2)2 + (y1 - y2)2 + (z1 - z2)2 ) diff_r = ((rgb[0] + brightness) - color.rgb[0]) * ( (rgb[0] + brightness) - color.rgb[0]) diff_g = ((rgb[1] + brightness) - color.rgb[1]) * ( (rgb[1] + brightness) - color.rgb[1]) diff_b = ((rgb[2] + brightness) - color.rgb[2]) * ( (rgb[2] + brightness) - color.rgb[2]) x = min(diff_r, diff_g, diff_b) z = max(diff_r, diff_g, diff_r) y = (diff_r + diff_g + diff_b) - (x + z) x = x / sensitive z = z * sensitive diffys = math.sqrt(x + y + z) if diffys < diff_min[1]: diff_min[1] = diffys diff_min[0] = color.rgb #return rounding colour if not silent: print( I18n.get(' %s colours rounded %s (%s) ') % (str(rgb), str(diff_min[0]), I18n.get(str(EnumColor.rgb(diff_min[0]).name), 'true'))) return EnumColor.rgb(diff_min[0])
def apply(self): px_total = self.bot.image.height * self.bot.image.width px_ok = 0 px_not_yet = 0 for y in xrange(self.bot.image.height): for x in xrange(self.bot.image.width): color = EnumColor.rgb(self.bot.image.pix[x,y]) px_ok = px_ok + 1 if self.bot.canvas.get_color(self.bot.start_x + x, self.bot.start_y + y) != color and not color in self.colors_ignored: px_not_yet = px_not_yet + 1 px_ok = px_ok - 1 print(I18n.get('Total: %s painted: %s Not painted %s') % (str(px_total), str(px_ok), str(px_not_yet))) time.sleep(60)
def wait_time(self, data = {'waitSeconds':None}): def complete(i, wait): return ((100 * (float(i) / float(wait))) * 20) / 100 if data['waitSeconds'] is not None: wait = data['waitSeconds'] + (random.randint(0, 9) / 10.0) print(I18n.get('Waiting %s seconds') % str(wait)) c = i = 0 while c < 20: c = complete(i, wait) time.sleep(wait - i if i == int(wait) else 1) out.write("[{}]\0\r".format('+' * int(c) + '-' * (20 - int(c)))) out.flush() i += 1 out.write("\n") out.flush()
def rgb(rgb): for color in EnumColor.ENUM: if rgb == color.rgb: return color #if that colors not in standart colors list diff_min = [(255,255,255), 441.7] # sqrt(255*255 + 255*255 + 255*255) = 441.67295593 --> Default white for color in EnumColor.ENUM: #formula that sqrt( (x1 - x2)2 + (y1 - y2)2 + (z1 - z2)2 ) diffys = math.sqrt( (rgb[0] - color.rgb[0]) * (rgb[0] - color.rgb[0]) + (rgb[1] - color.rgb[1]) * (rgb[1] - color.rgb[1]) + (rgb[2] - color.rgb[2]) * (rgb[2] - color.rgb[2])) if diffys < diff_min[1]: diff_min[1] = diffys diff_min[0] = color.rgb #return rounding colour print(I18n.get(' %s colours rounded %s (%s) ') % (str(rgb) , str(diff_min[0]), I18n.get(str(EnumColor.rgb(diff_min[0]).name)))) return EnumColor.rgb(diff_min[0])
def wait_time(self, data = {'waitSeconds':None}): if data['waitSeconds'] is not None: wait = data['waitSeconds'] print(I18n.get('Waiting %s seconds') % str(wait)) time.sleep(wait)
def on_open(ws): print(I18n.get("Websocket open"))
def on_close(ws): print(I18n.get("### closed ###")) open_connection()