当前位置: 首页>>代码示例>>Python>>正文


Python Object.getRealPosition方法代码示例

本文整理汇总了Python中Object.Object.getRealPosition方法的典型用法代码示例。如果您正苦于以下问题:Python Object.getRealPosition方法的具体用法?Python Object.getRealPosition怎么用?Python Object.getRealPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Object.Object的用法示例。


在下文中一共展示了Object.getRealPosition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from Object import Object [as 别名]
# 或者: from Object.Object import getRealPosition [as 别名]

#.........这里部分代码省略.........
            x = objStartX - 2.0 * HALF_W + (1 + i / 4) * kilobotOffsets[i % 4, 0]
            y = objStartY + (1 + i / 4) * kilobotOffsets[i % 4, 1]
            kilobot.body.position = vec2(x, y) * self.SCALE_REAL_TO_SIM

        s = asmatrix(empty((1, 2 + 2 * self.numKilobots)))
        targetPos = matrix([objStartX, objStartY])

        while True:
            """ user interaction """
            # handle keys
            for event in pygame.event.get():
                if event.type == KEYDOWN:
                    if event.key == K_PLUS:
                        self.stepsPerSec *= 2
                    elif event.key == K_MINUS:
                        self.stepsPerSec = np.max([1, self.stepsPerSec / 2])

            """ drawing """
            self.screen.fill((0, 0, 0, 0))

            self.maze.draw(self.screen)
            self.pushObject.draw(self.screen)

            for kilobot in self.kilobots:
                kilobot.draw(self.screen)

            # draw light
            lx = int(self.SCALE_REAL_TO_VIS * lightPos[0, 0])
            ly = int(self.screen.get_height() - self.SCALE_REAL_TO_VIS *
                    lightPos[0, 1])
            lr = int(self.SCALE_REAL_TO_VIS * 0.02)
            gfxdraw.aacircle(self.screen, lx, ly, lr, (255, 255, 0))

            objPos = self.pushObject.getRealPosition()

            # draw line from object to target position
            ox = int(self.SCALE_REAL_TO_VIS * objPos[0, 0])
            oy = int(self.screen.get_height() - self.SCALE_REAL_TO_VIS *
                    objPos[0, 1])
            tx = int(self.SCALE_REAL_TO_VIS * targetPos[0, 0])
            ty = int(self.screen.get_height() - self.SCALE_REAL_TO_VIS *
                    targetPos[0, 1])

            pygame.draw.aaline(self.screen, (0, 0, 255), (ox, oy), (tx, ty))

            pygame.display.flip()
            self.clock.tick(self.stepsPerSec)

            """ simulation """
            # current state
            s[0, 0] = lightPos[0, 0] - objPos[0, 0]
            s[0, 1] = lightPos[0, 1] - objPos[0, 1]

            for (i, kilobot) in zip(range(self.numKilobots), self.kilobots):
                kbPos = kilobot.getRealPosition()
                s[0, 2 + 2 * i + 0] = kbPos[0, 0] - objPos[0, 0]
                s[0, 2 + 2 * i + 1] = kbPos[0, 1] - objPos[0, 1]

            # solve maze
            targetPos = self.mazePolicy.getTargetPosition(objPos)

            # rotate state
            direction = targetPos - objPos
            angle = -math.atan2(direction[0, 1], direction[0, 0])

            sx = s.flat[0::2] * math.cos(angle) - s.flat[1::2] * math.sin(angle)
开发者ID:tu-darmstadt-kilobots,项目名称:kbSimulator,代码行数:70,代码来源:simulate_maze.py

示例2: __init__

# 需要导入模块: from Object import Object [as 别名]
# 或者: from Object.Object import getRealPosition [as 别名]

#.........这里部分代码省略.........
            for step in range(self.numStepsPerEpisode):
                """ user interaction """
                # handle keys
                for event in pygame.event.get():
                    if event.type == KEYDOWN:
                        if event.key == K_PLUS:
                            self.stepsPerSec *= 2
                        elif event.key == K_MINUS:
                            self.stepsPerSec = np.max([1, self.stepsPerSec / 2])

                """ drawing """
                self.screen.fill((0, 0, 0, 0))

                self.pushObject.draw(self.screen)

                for kilobot in self.kilobots:
                    kilobot.draw(self.screen)

                # draw light
                lx = int(self.SCALE_REAL_TO_VIS * lightPos[0, 0])
                ly = int(self.screen.get_height() - self.SCALE_REAL_TO_VIS *
                        lightPos[0, 1])
                lr = int(self.SCALE_REAL_TO_VIS * 0.02)
                gfxdraw.aacircle(self.screen, lx, ly, lr, (255, 255, 0))

                pygame.display.set_caption(('ep: {} - step: {} - ' +
                    'stepsPerSec: {}').format(ep + 1, step + 1, self.stepsPerSec))

                pygame.display.flip()
                self.clock.tick(self.stepsPerSec)

                """ simulation """
                # current state
                objPos = self.pushObject.getRealPosition()
                objPosOld = objPos

                s = asmatrix(empty((1, S.shape[1])))
                s[0, 0] = lightPos[0, 0] - objPos[0, 0]
                s[0, 1] = lightPos[0, 1] - objPos[0, 1]

                for (i, kilobot) in zip(range(self.numKilobots), self.kilobots):
                    kbPos = kilobot.getRealPosition()
                    s[0, 2 + 2 * i + 0] = kbPos[0, 0] - objPos[0, 0]
                    s[0, 2 + 2 * i + 1] = kbPos[0, 1] - objPos[0, 1]

                # choose action
                if self.useMean:
                    a = self.policy.getMeanAction(s)
                else:
                    if random.random() <= self.epsilon:
                        a = self.policy.getRandomAction()
                    else:
                        a = self.policy.sampleActions(s)

                # take action
                n = linalg.norm(a)
                if n > 0.015:
                    lightPos += (a * 0.015 / n)
                else:
                    lightPos += a

                # move directly toward the light
                for kilobot in self.kilobots:
                    kbPos = kilobot.getRealPosition()

                    v = lightPos - kbPos
开发者ID:tu-darmstadt-kilobots,项目名称:kbSimulator,代码行数:70,代码来源:simulate_single_direction.py


注:本文中的Object.Object.getRealPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。