Пример #1
0
    def on_mouse_down(self, button, pos):
        tsize = psi.config.TILE_PIXEL_SIZE
        update = False
        if button == psi.MOUSE_RIGHT:
            self.center = psi.calc.virtual_coord(pos)
            self.center = psi.calc.snap_to_grid(self.center)
            update = True

        if button == psi.MOUSE_LEFT:
            self.mark = psi.calc.virtual_coord(pos)
            self.mark = psi.calc.snap_to_grid(self.mark)
            update = True

        if update:

            d = scipy.spatial.distance.euclidean(self.center, self.mark)
            th = np.rad2deg(np.arctan2(self.center[1]-self.mark[1], self.center[0]-self.mark[0]))

            self.inside = set()
            self.aux = []

            timer = Timer()
            timer.tic
            points = bresenham(int(self.center[0]), int(self.center[1]), int(self.mark[0]), int(self.mark[1]), tsize)
            self.inside.update(points)
            for angle in xrange(-15, 15, 2):
                # angle = a_/2.
                r = psi.calc.rotation_matrix(angle)
                p = (Vector2(*r.dot(self.mark-self.center).tolist()))+self.center

                points = bresenham(int(self.center[0]), int(self.center[1]), int(p[0]), int(p[1]), tsize)
                self.inside.update(points)
            t = timer.toc()
            print '\n::: %.4f seconds.'%t
Пример #2
0
    def on_pre_load(self):
        print 'at psi.graphics.on_pre_load'
        timer = Timer()
        timer.tic()

        tile_size = psi.config.TILE_PIXEL_SIZE
        n_tile = psi.config.MAX_TILE
        center = n_tile//2
        
        n = n_tile*n_tile*4
        self._mapgrid_vertexes = np.zeros([n, 2], dtype='float32')
        self._mapgrid_colors = np.zeros([n, 4], dtype='float32')
        # self._mapgrid_colors = np.random.random([n, 4]).astype('float32')

        i = 0
        start = (0-center)*tile_size
        end = (n_tile-center)*tile_size

        tiles = itertools.product(
            xrange(start, end, tile_size), 
            xrange(start, end, tile_size)
        )
        v = self._mapgrid_vertexes
        for row, col in tiles:
            x1, y1 = col, row
            x2, y2 = x1+tile_size, y1+tile_size
            # if i>10: raw_input()
            # print [[x1, y1], [x2, y1], [x2, y2], [x1, y2]]
            v[i:i+4, :] = [[x1, y1], [x2, y1], [x2, y2], [x1, y2]]
            i += 4
        
        # v = self._mapgrid_vertexes
        # row_cont = 0
        # for row in xrange(start, end, tile_size):
        #     # for col in xrange(start, end, tile_size):
        #     col_cont = row_cont
        #     for col in xrange(row, end, tile_size):
        #         x1, y1 = col, row
        #         x2, y2 = x1+tile_size, y1+tile_size
                
        #         j = col_cont*(4*n_tile) + row_cont*4
        #         v[i:i+4, :] = [[x1, y1], [x2, y1], [x2, y2], [x1, y2]]
        #         v[j:j+4, :] = [[y1, x1], [y1, x2], [y2, x2], [y2, x1]]
        #         # v[(i+0)] = [x1, y1]
        #         # v[(i+1)] = [x2, y1]
        #         # v[(i+2)] = [x2, y2]
        #         # v[(i+3)] = [x1, y2]

        #         # v[(j+0)] = [y1, x1]
        #         # v[(j+1)] = [y1, x2]
        #         # v[(j+2)] = [y2, x2]
        #         # v[(j+3)] = [y2, x1]

        #         i+=4
        #         col_cont += 1

        #     row_cont += 1
        #     i += 4*row_cont

        self._mapgrid_vertexbuffer = VBO(self._mapgrid_vertexes)

        s = timer.toc()
        print 'Timer elapsed: %.4f seconds'%s
Пример #3
0
    def on_pre_load(self):
        print 'at psi.graphics.on_pre_load'
        timer = Timer()
        timer.tic()

        tile_size = psi.config.TILE_PIXEL_SIZE
        n_tile = psi.config.MAX_TILE
        center = n_tile // 2

        n = n_tile * n_tile * 4
        self._mapgrid_vertexes = np.zeros([n, 2], dtype='float32')
        self._mapgrid_colors = np.zeros([n, 4], dtype='float32')
        # self._mapgrid_colors = np.random.random([n, 4]).astype('float32')

        i = 0
        start = (0 - center) * tile_size
        end = (n_tile - center) * tile_size

        tiles = itertools.product(xrange(start, end, tile_size),
                                  xrange(start, end, tile_size))
        v = self._mapgrid_vertexes
        for row, col in tiles:
            x1, y1 = col, row
            x2, y2 = x1 + tile_size, y1 + tile_size
            # if i>10: raw_input()
            # print [[x1, y1], [x2, y1], [x2, y2], [x1, y2]]
            v[i:i + 4, :] = [[x1, y1], [x2, y1], [x2, y2], [x1, y2]]
            i += 4

        # v = self._mapgrid_vertexes
        # row_cont = 0
        # for row in xrange(start, end, tile_size):
        #     # for col in xrange(start, end, tile_size):
        #     col_cont = row_cont
        #     for col in xrange(row, end, tile_size):
        #         x1, y1 = col, row
        #         x2, y2 = x1+tile_size, y1+tile_size

        #         j = col_cont*(4*n_tile) + row_cont*4
        #         v[i:i+4, :] = [[x1, y1], [x2, y1], [x2, y2], [x1, y2]]
        #         v[j:j+4, :] = [[y1, x1], [y1, x2], [y2, x2], [y2, x1]]
        #         # v[(i+0)] = [x1, y1]
        #         # v[(i+1)] = [x2, y1]
        #         # v[(i+2)] = [x2, y2]
        #         # v[(i+3)] = [x1, y2]

        #         # v[(j+0)] = [y1, x1]
        #         # v[(j+1)] = [y1, x2]
        #         # v[(j+2)] = [y2, x2]
        #         # v[(j+3)] = [y2, x1]

        #         i+=4
        #         col_cont += 1

        #     row_cont += 1
        #     i += 4*row_cont

        self._mapgrid_vertexbuffer = VBO(self._mapgrid_vertexes)

        s = timer.toc()
        print 'Timer elapsed: %.4f seconds' % s