Exemplo n.º 1
0
    def on_init(self):
        self._pos = Vector2(0, 0)
        self._th = 0.0
        self.size = Vector2(45, 38)
        self.aux = []

        self._data_pos = None
        self._data_th = None
        self._data_sonar = None
        self._data_index = None
Exemplo n.º 2
0
    def __setstate__(self, state):
        self._initial_value = state['_initial_value']
        self._size = state['_size']
        self._center = Vector2(self._size // 2, self._size // 2)
        self._map = None

        self._min_pos_real = self._center.copy()
        self._max_pos_real = self._center.copy()
        self.min_pos = Vector2(0, 0)
        self.max_pos = Vector2(0, 0)

        self.clear()
Exemplo n.º 3
0
    def __init__(self, size=None, initial_value=None):
        self._initial_value = initial_value
        self._size = size or psi.config.MAX_TILE
        self._center = Vector2(self._size // 2, self._size // 2)
        self._map = None

        self._min_pos_real = self._center.copy()
        self._max_pos_real = self._center.copy()
        self.min_pos = Vector2(0, 0)
        self.max_pos = Vector2(0, 0)

        self.clear()
Exemplo n.º 4
0
    def on_draw(self, tick):
        tsize = psi.config.TILE_PIXEL_SIZE
        ht = tsize/2
        # for pos in self.marks:       

        psi.graphics.draw_box(200, 0, tsize, tsize, psi.CYAN)
        psi.graphics.draw_box(0, 200, tsize, tsize, psi.CYAN)
        psi.graphics.draw_box(200, 200, tsize, tsize, psi.CYAN)
        psi.graphics.draw_box(-200, 0, tsize, tsize, psi.CYAN)
        psi.graphics.draw_box(0, -200, tsize, tsize, psi.CYAN)
        psi.graphics.draw_box(-200, -200, tsize, tsize, psi.CYAN)
        psi.graphics.draw_box(-200, 200, tsize, tsize, psi.CYAN)
        psi.graphics.draw_box(200, -200, tsize, tsize, psi.CYAN)
            
        for i in self.inside:
            psi.graphics.draw_box(i[0], i[1], tsize, tsize, (.3, .3, .3, .5))

        for i in self.outside:
            psi.graphics.draw_box(i[0], i[1], tsize, tsize, (.2, .6, .2, .5))

        for a in self.aux:
            ax = Vector2(a[0], a[1])
            psi.graphics.draw_box(ax.x, ax.y, tsize, tsize, psi.BLUE)
            psi.graphics.draw_line([self.center+[ht, ht], ax+(ht, ht)])
            psi.graphics.draw_line([self.mark+(ht, ht), ax+(ht, ht)])

        if self.mark is not None:
            psi.graphics.draw_box(self.mark.x, self.mark.y, tsize, tsize, psi.GREEN)
            psi.graphics.draw_box(self.center.x, self.center.y, tsize, tsize, psi.GREEN)
            psi.graphics.draw_line([self.center+[ht, ht], self.mark+(ht, ht)])
Exemplo n.º 5
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
Exemplo n.º 6
0
    def on_draw(self, event):
        dc = wx.PaintDC(self)
        self.SetCurrent()

        if not self.initialized:
            self.initialized = True
            self.canvas_size = Vector2(*self.GetSize())
            psi.app.on_init()
Exemplo n.º 7
0
 def on_init(self):
     self.mark = None
     self.aux = []
     self.inside = []
     self.outside = []
     self.center = Vector2(0, 0)
     self.var = 'lol'
     self.lll = 'lll'
     self.component = None
Exemplo n.º 8
0
    def __init__(self):
        self._is_middle_down = False
        self._last_mouse_position = Vector2(0, 0)

        self._render_batch = RenderBatch(GL_QUADS)
        self._overlay_batch = RenderBatch(GL_LINES)
        self._grid = None
        self._mapgrid_colors = None
        self._mapgrid_vertexes = None
        self._mapgrid_vertexbuffer = None
        self._batches = []
        self.camera = Camera()
Exemplo n.º 9
0
    def __init__(self, parent):
        super(CanvasWidget, self).__init__(parent, -1)

        self.initialized = False
        self.mouse_position = None
        self.canvas_size = Vector2(0, 0)

        self.Bind(wx.EVT_PAINT, self.on_draw)
        self.Bind(wx.EVT_SIZE, self.on_resize)
        # self.Bind(wx.EVT_IDLE, self.on_idle)

        self.Bind(wx.EVT_LEFT_DOWN, self.on_mouse_down)
        self.Bind(wx.EVT_LEFT_UP, self.on_mouse_up)
        self.Bind(wx.EVT_MIDDLE_DOWN, self.on_mouse_down)
        self.Bind(wx.EVT_MIDDLE_UP, self.on_mouse_up)
        self.Bind(wx.EVT_RIGHT_DOWN, self.on_mouse_down)
        self.Bind(wx.EVT_RIGHT_UP, self.on_mouse_up)
        self.Bind(wx.EVT_MOUSEWHEEL, self.on_mouse_wheel)
        self.Bind(wx.EVT_MOTION, self.on_mouse_motion)

        if wx.Platform == '__WXMSW__':
            self.Bind(wx.EVT_LEFT_DCLICK, self.on_mouse_down)
            self.Bind(wx.EVT_RIGHT_DCLICK, self.on_mouse_down)
            self.Bind(wx.EVT_MIDDLE_DCLICK, self.on_mouse_down)
Exemplo n.º 10
0
 def on_mouse_motion(self, event):
     x, y = event.GetPosition()
     pos = Vector2(x, self.canvas_size.y - y)
     self.mouse_position = pos
     psi.app.on_mouse_motion(pos)
Exemplo n.º 11
0
 def on_resize(self, event):
     size = Vector2(*event.GetSize())
     psi.app.on_window_resize(size)
Exemplo n.º 12
0
 def __init__(self, pos=Vector2(0, 0)):
     self.pos = pos
     self.half_size = Vector2(300, 300)
     self.zoom = 1.0
     self._zoom_step = 0.5
     self._scale_rate = 1 / self.zoom
Exemplo n.º 13
0
 def __init__(self):
     super(BaseRobot, self).__init__()
     self.pos = Vector2(0, 0)
     self.th = 0.0
     self.size = Vector2(45, 38) # robot size by cm