示例#1
0
    def setup_canvas(self):
        point_x, point_y = CalcAxis.calc_middle_axis(self.start_x,
                                                     self.image.width,
                                                     self.start_y,
                                                     self.image.height)
        radius = CalcAxis.calc_radius(self.start_x, self.image.width,
                                      self.start_y, self.image.height)
        iteration = CalcAxis.calc_iteration(radius)
        axis_x, axis_y = CalcAxis.calc_centers_axis(point_x, point_y)
        canvas = Matrix(iteration, axis_x, axis_y)

        for center_x in xrange(axis_x - iteration, 1 + axis_x + iteration, 15):
            for center_y in xrange(axis_y - iteration, 1 + axis_y + iteration,
                                   15):
                raw = self.pixelio.download_canvas(center_x, center_y)
                index = 0
                for block_y in xrange(center_y - 7, center_y + 8):
                    for block_x in xrange(center_x - 7, center_x + 8):
                        for y in xrange(64):
                            actual_y = (block_y * 64) + y
                            for x in xrange(0, 64, 2):
                                actual_x = (block_x * 64) + x
                                canvas.update(
                                    actual_x, actual_y,
                                    EnumColor.index(ord(raw[index]) >> 4))
                                canvas.update(
                                    actual_x + 1, actual_y,
                                    EnumColor.index(ord(raw[index]) & 0x0F))
                                index += 1
        return canvas
示例#2
0
    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
示例#3
0
 def roll_dice(self, canvas):
     rnd_x = rnd_y = color = None
     while all(v is None
               for v in [rnd_x, rnd_y, color]) or canvas.get_color(
                   rnd_x, rnd_y) == color:
         rnd_x = self.random(self.bot.start_x,
                             self.bot.start_x + self.bot.image.width - 1)
         rnd_y = self.random(self.bot.start_y,
                             self.bot.start_y + self.bot.image.height - 1)
         color = EnumColor.rgb(
             self.bot.image.pix[rnd_x - self.bot.start_x,
                                rnd_y - self.bot.start_y], True)
     color = EnumColor.rgb(self.bot.image.pix[rnd_x - self.bot.start_x,
                                              rnd_y - self.bot.start_y])
     return rnd_x, rnd_y, color
示例#4
0
 def roll_dice(self, canvas):
     rnd_x = self.random(self.bot.start_x, self.bot.start_x + self.bot.image.width  - 1)
     rnd_y = self.random(self.bot.start_y, self.bot.start_y + self.bot.image.height - 1)
     color = EnumColor.rgb(self.bot.image.pix[rnd_x - self.bot.start_x, rnd_y - self.bot.start_y])
     if canvas.get_color(rnd_x, rnd_y) == color:
         return self.roll_dice(canvas)
     return rnd_x, rnd_y, color
示例#5
0
    def apply(self):
        _startX = int(math.floor((self.bot.image.width - 1) / 2))
        _startY = int(math.floor((self.bot.image.height - 1) / 2))

        _currentX = _startX
        _currentY = _startY

        while True:

            color = EnumColor.rgb(self.bot.image.pix[_currentX, _currentY],
                                  True)
            if self.bot.canvas.get_color(
                    self.bot.start_x + _currentX, self.bot.start_y + _currentY
            ) != color and not color in self.colors_ignored and self.bot.canvas.get_color(
                    self.bot.start_x + _currentX, self.bot.start_y +
                    _currentY) not in self.colors_not_overwrite:
                self.bot.paint(self.bot.start_x + _currentX,
                               self.bot.start_y + _currentY, color)
                _currentX = _startX
                _currentY = _startY

            if (random.random() < 0.5):
                if (random.random() < 0.5):
                    _currentX += 1
                else:
                    _currentX += -1
            else:
                if (random.random() < 0.5):
                    _currentY += 1
                else:
                    _currentY += -1

            if _currentX >= self.bot.image.width or _currentY >= self.bot.image.height or _currentX < 0 or _currentY < 0:
                _currentX = _startX
                _currentY = _startY
示例#6
0
 def __init__(self, image, fingerprint, start_x, start_y, mode_defensive, colors_ignored, proxy = None , draw_strategy = 'randomize'):
     self.image = image
     self.start_x = start_x
     self.start_y =  start_y
     self.mode_defensive = mode_defensive
     self.strategy = FactoryStrategy.build(draw_strategy, self, [EnumColor.index(i) for i in colors_ignored])
     self.pixelio = PixelCanvasIO(fingerprint, proxy)
     self.print_all_websocket_log = False#TODO make an argument
示例#7
0
 def match(self, canvas, image):
     for x in xrange(0, image.width):
         for y in xrange(0, image.height):
             if canvas.get_color(x + self.bot.start_x,
                                 y + self.bot.start_y) != EnumColor.rgb(
                                     self.bot.image.pix[x, y]):
                 return False
     return True
示例#8
0
 def apply(self):
     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])
             if self.bot.canvas.get_color(
                     self.bot.start_x + x, self.bot.start_y +
                     y) != color and not color in self.colors_ignored:
                 self.bot.paint(self.bot.start_x + x, self.bot.start_y + y,
                                color)
示例#9
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)
示例#10
0
 def apply(self):
     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], True)
             if self.bot.canvas.get_color(
                     self.bot.start_x + x, self.bot.start_y + y
             ) != color and not color in self.colors_ignored and self.bot.canvas.get_color(
                     self.bot.start_x + x,
                     self.bot.start_y + y) not in self.colors_not_overwrite:
                 if (x % 2 == self.b):
                     self.bot.paint(self.bot.start_x + x,
                                    self.bot.start_y + y, color)
         self.b = not self.b
     self.b = False
示例#11
0
    def convert_pixels(self, image):
        width, height = image.size

        new = self.create_image(width, height)
        pixels = new.load()

        for i in range(width):
            for j in range(height):
                pixel = self.get_pixel(image, i, j)
                new_color = EnumColor.rgb(pixel, True, self.sensitive,
                                          self.brightness)
                pixels[i, j] = (int(new_color.rgb[0]), int(new_color.rgb[1]),
                                int(new_color.rgb[2]))

        return new
示例#12
0
 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