本文整理汇总了Python中Object.Object.draw方法的典型用法代码示例。如果您正苦于以下问题:Python Object.draw方法的具体用法?Python Object.draw怎么用?Python Object.draw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Object.Object
的用法示例。
在下文中一共展示了Object.draw方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Object import Object [as 别名]
# 或者: from Object.Object import draw [as 别名]
#.........这里部分代码省略.........
objStartY = 0.75
r = self.kilobots[0].RADIUS
kilobotOffsets = array([[-r, -r], [r, -r], [-r, r], [r, r]])
self.pushObject.body.position = vec2(objStartX, objStartY) *\
self.SCALE_REAL_TO_SIM
self.pushObject.body.angle = 0
# light starts over the object
lightPos = matrix([objStartX, objStartY])
HALF_W = self.pushObject.HALF_W
# kilobots start left of the object
for (i, kilobot) in zip(range(self.numKilobots), self.kilobots):
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
示例2: int
# 需要导入模块: from Object import Object [as 别名]
# 或者: from Object.Object import draw [as 别名]
light_pos[0, 1] -= 0.1
elif event.key == K_LEFT:
light_pos[0, 0] -= 0.1
elif event.key == K_SPACE:
paused = not paused
elif event.key == K_PLUS:
time_step = time_step + 0.01
elif event.key == K_MINUS:
time_step = time_step - 0.01
env['light_pos'] = light_pos
# draw labyrinth and object
screen.fill((0, 0, 0, 0))
labyrinth.draw(screen)
push_object.draw(screen)
# draw light
light_pos = env['light_pos']
lx = int(SCALE_REAL_TO_VIS * light_pos[0, 0])
ly = int(screen.get_height() - SCALE_REAL_TO_VIS * light_pos[0, 1])
gfxdraw.aacircle(screen, lx, ly, 5, (255, 255, 0, 255))
# handle kilobot movement and drawing
for kb in kilobots:
kb.step()
kb.setVelocities()
kb.draw(screen)
if not paused:
# step physics objects using 10 pos and vel update iterations
示例3: __init__
# 需要导入模块: from Object import Object [as 别名]
# 或者: from Object.Object import draw [as 别名]
#.........这里部分代码省略.........
# s: light.x light.y kb.x1 kb.y1 ... kb.xn kb.yn
# everything is relative to the object position
# a: light movement (dx, dy)
S = asmatrix(empty((numSamples, 2 + 2 * self.numKilobots)))
A = asmatrix(empty((numSamples, 2)))
R = asmatrix(empty((numSamples, 1)))
S_ = asmatrix(empty((numSamples, 2 + 2 * self.numKilobots)))
for ep in range(startPositions.shape[0]):
self.pushObject.body.position = vec2(objStartX, objStartY) *\
self.SCALE_REAL_TO_SIM
self.pushObject.body.angle = 0
# light starts in circel around the object
start = startPositions[ep, :]
lightPos = matrix(start)
# kilobots start at the light position in a fixed formation
for (i, kilobot) in zip(range(self.numKilobots), self.kilobots):
x = start[0] + (1 + i / 4) * kilobotOffsets[i % 4, 0]
y = start[1] + (1 + i / 4) * kilobotOffsets[i % 4, 1]
kilobot.body.position = vec2(x, y) * self.SCALE_REAL_TO_SIM
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]