本文整理汇总了Python中cube.Cube.rotate方法的典型用法代码示例。如果您正苦于以下问题:Python Cube.rotate方法的具体用法?Python Cube.rotate怎么用?Python Cube.rotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cube.Cube
的用法示例。
在下文中一共展示了Cube.rotate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestCube
# 需要导入模块: from cube import Cube [as 别名]
# 或者: from cube.Cube import rotate [as 别名]
class TestCube(unittest.TestCase):
def setUp(self):
self.c = Cube()
def test_rotate(self):
faces = ['front','back','right','left','up','down']
for face in faces:
self.c.rotate(face, 'r').rotate(face, 'l')
self.assertTrue(self.c.is_solved())
for dir_ in ['r','l']:
for i in range(4):
self.c.rotate(face, dir_)
self.assertTrue(self.c.is_solved())
示例2: main_loop
# 需要导入模块: from cube import Cube [as 别名]
# 或者: from cube.Cube import rotate [as 别名]
def main_loop(screen):
""" Run the main game loop. """
cube = Cube()
the_renderer = renderer.Renderer(screen)
projection = 'default'
show_help = True
while True:
screen.erase()
screen.box()
the_renderer.render(cube, projection)
if show_help:
the_renderer.add_help_strings()
if cube.solved:
the_renderer.add_solved_string()
screen.refresh()
key = screen.getkey()
logging.debug('Key press {}'.format(key))
if key == 'KEY_F(1)':
show_help = not show_help
elif key == '1':
projection = 'default' # Front view
elif key == '3':
projection = 'multi' # Orthographic projection view
elif key == 'x':
cube.rotate(0) # Rotate about x-axis
elif key == 'X':
cube.rotate(0, sign=-1) # Rotate about x-axis in CCW direction
elif key == 'y':
cube.rotate(1)
elif key == 'Y':
cube.rotate(1, sign=-1)
elif key == 'z':
cube.rotate(2)
elif key == 'Z':
cube.rotate(2, sign=-1)
elif key == 'j':
cube.twist('top')
elif key == 'J':
cube.twist('top', sign=-1)
elif key == 'i':
cube.twist('middle') # horizontal
elif key == 'I':
cube.twist('middle', sign=-1)
elif key == 'k':
cube.twist('bottom')
elif key == 'K':
cube.twist('bottom', sign=-1)
elif key == 'h':
cube.twist('left')
elif key == 'H':
cube.twist('left', sign=-1)
elif key == 'm':
cube.twist('center') # vertical
elif key == 'M':
cube.twist('center', sign=-1)
elif key == 'l':
cube.twist('right')
elif key == 'L':
cube.twist('right', sign=-1)
elif key == 's':
cube.scramble()
elif key == 'S':
cube.solve()
elif key == 'q':
break # Exit the while loop
screen.erase() # Avoid flashing reset colours
screen.refresh()
示例3: Cubr
# 需要导入模块: from cube import Cube [as 别名]
# 或者: from cube.Cube import rotate [as 别名]
#.........这里部分代码省略.........
# Superclass deals with packing canvas
self.controlPane.pack(expand=1, fill=Tkinter.BOTH)
self.newCube()
def newCube(self):
# replaces self.cube with a new Cube() object
if hasattr(self, 'cube'):
self.cube.cleanup()
del self.cube
self.cube = Cube(self.canvas, self.controlPane, self)
def received(self, cube):
# callback handler for the screenGrabber module
# sets self.cube's configuration based on the Streamer cube
self.inCam = False
self.cube.helpState = self.cube.INGAME
if self.cube.debug:
print cube.events
try:
self.cube.setConfig(cube)
except:
# Something went wrong setting the configuration
self.cube.state.setSolved()
def fromCamera(self):
# Create "Starting webcam..." popup while we wait for webcam to turn on
self.canvas.create_rectangle(self.width/2 - 200, self.height/2 - 50,
self.width/2 + 200, self.height/2 + 50,
fill='#123456', outline='#abcdef', width=5)
self.canvas.create_text(self.width/2, self.height/2, fill='#ffffff',
font='Arial 36 bold', text='Starting webcam...')
self.canvas.update()
self.newCube()
self.inCam = True
# Hand over control to the screenGrabber
screenGrabber.cubeFromCam(app=self, callback=self.received)
def timerFired(self):
# cube.timer wrapper -- only calls if we are not in screenGrabber
if not self.inCam:
self.cube.timer()
def debug(self):
# toggle whether debug is on or off. this feature is disabled in release builds.
self.cube.debug = not self.cube.debug
self.cube.redraw()
def resize(self, event):
# Event binding for canvas resizing
self.width = event.width
self.height = event.height
self.resized = True
self.cube.width = self.width
self.cube.height = self.height
self.cube.camera.width = self.width
self.cube.camera.height = self.height
def mousePressed(self, event):
# Wrapper for cube.click
self.cube.click(event)
def controlResize(self, event):
# Event binding for controlPane resizing
# Adjust size, and compensate for border
borderX, borderY = -7, -6
self.controlPane.config(width=event.width+borderX,
height=event.height+borderY)
self.cube.configureControls(self.controlPane)
def keyPressed(self, event):
# key event handler
# Adjust viewmode. only available in debug.
if self.cube.debug:
if event.keysym == 'o':
self.cube.camera.fisheye(+1.2)
self.cube.redraw()
elif event.keysym == 'p':
self.cube.camera.fisheye(+0.8)
self.cube.redraw()
amt = self.cube.amt # Delta value for rotation sensitivity
if event.keysym == 'Left': self.cube.direction = (amt, self.cube.direction[1])
elif event.keysym == 'Right': self.cube.direction = (-amt, self.cube.direction[1])
elif event.keysym == 'Up': self.cube.direction = (self.cube.direction[0], amt)
elif event.keysym == 'Down': self.cube.direction = (self.cube.direction[0], -amt)
# command for clockwise rotation of a face
elif event.keysym in 'rdlufb': self.cube.rotate(event.keysym.upper())
# command for counterclockwise rotation of a face
elif event.keysym in 'RDLUFB': self.cube.rotate(event.keysym + "'")
else:
if self.cube.debug:
print event.keysym
def keyReleased(self, event):
if event.keysym in ['Left', 'Right', 'Down', 'Up']:
# stopping rotation
self.cube.direction = (0, 0)