Exemplo n.º 1
0
    def reducematrix(self):
        self.matrix = []
        minx = None
        maxx = None
        miny = None
        maxy = None

        with misc.timeit() as t:
            for i in range(len(self.elements) - 1):  # all but last
                # take the current
                origin = self.elements[i]
                # and the next
                point = self.elements[i + 1]

                # and get all pixels in between
                points = misc.allpoints(origin, point)

                for p in points:
                    if p not in self.matrix:

                        if minx is None or p[0] < minx:
                            minx = p[0]
                        if maxx is None or p[0] > maxx:
                            maxx = p[0]
                        if miny is None or p[1] < miny:
                            miny = p[1]
                        if maxy is None or p[1] > maxy:
                            maxy = p[1]

                        self.matrix.append(p)
        print('- Calc all points')

        # ajust to the minimum coord
        for p in self.matrix:
            p[0] = p[0] - minx
            p[1] = p[1] - miny

        # print('matrix', self.matrix)
        if maxx is not None:
            size = max(maxx - minx, maxy - miny)
            # print('  minx', minx, 'miny', miny, 'maxx', maxx, 'maxy', maxy, 'size', size)
        else:
            size = self.width

        with misc.timeit() as t:
            self.scaled = misc.scalematrix(self.matrix, (size, size), (15, 15))
        # finally:
        print('- Scale matrix')
Exemplo n.º 2
0
    def reducematrix(self):
        self.matrix = []
        minx = None
        maxx = None
        miny = None
        maxy = None

        with misc.timeit() as t:
            for i in range(len(self.elements) - 1):  # all but last
                # take the current
                origin = self.elements[i]
                # and the next
                point = self.elements[i + 1]

                # and get all pixels in between
                points = misc.allpoints(origin, point)

                for p in points:
                    if p not in self.matrix:

                        if minx is None or p[0] < minx:
                            minx = p[0]
                        if maxx is None or p[0] > maxx:
                            maxx = p[0]
                        if miny is None or p[1] < miny:
                            miny = p[1]
                        if maxy is None or p[1] > maxy:
                            maxy = p[1]

                        self.matrix.append(p)
        print("- Calc all points")

        # ajust to the minimum coord
        for p in self.matrix:
            p[0] = p[0] - minx
            p[1] = p[1] - miny

        # print('matrix', self.matrix)
        if maxx is not None:
            size = max(maxx - minx, maxy - miny)
            # print('  minx', minx, 'miny', miny, 'maxx', maxx, 'maxy', maxy, 'size', size)
        else:
            size = self.width

        with misc.timeit() as t:
            self.scaled = misc.scalematrix(self.matrix, (size, size), (15, 15))
        # finally:
        print("- Scale matrix")
Exemplo n.º 3
0
    def on_touch_up(self, touch):
        if touch.grab_current is self:
            touch.ungrab(self)
            # print('elements', self.elements)

            # try:
            with misc.timeit() as t:
                self.reducematrix()
            # finally:
            print('Matrix reduction and redraw')

            self.oldxy = None
            return True

        return super(Pad, self).on_touch_up(touch)
Exemplo n.º 4
0
    def on_touch_up(self, touch):
        if touch.grab_current is self:
            touch.ungrab(self)
            # print('elements', self.elements)

            # try:
            with misc.timeit() as t:
                self.reducematrix()
            # finally:
            print("Matrix reduction and redraw")

            self.oldxy = None
            return True

        return super(Pad, self).on_touch_up(touch)