Beispiel #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
Beispiel #2
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
 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