Permalink
Browse files

ENH: GUI option for inner faces

  • Loading branch information...
1 parent a4e736c commit f6eb26a29de89ba7a25fd29a96e2f98d8078afa2 @jakevdp jakevdp committed Nov 26, 2012
Showing with 15 additions and 4 deletions.
  1. +3 −1 README.rst
  2. +12 −3 code/cube_interactive.py
View
@@ -38,7 +38,9 @@ Controls
- **Arrow keys** may also be used to change the viewing angle. The shift
key has the same effect
- **U/D/L/R/B/F** keys rotate the faces a quarter turn clockwise. Hold the
- shift key to rotate counter-clockwise.
+ shift key to rotate counter-clockwise. Hold a number i to turn the slab
+ at a depth i (e.g. for a 3x3 cube, holding "1" and pressing "L" will turn
+ the center slab).
Other
~~~~~
View
@@ -254,6 +254,7 @@ def __init__(self, cube=None,
self._button2 = False # true when button 2 is pressed
self._event_xy = None # store xy position of mouse event
self._shift = False # shift key pressed
+ self._digit_flags = np.zeros(10, dtype=bool) # digits 0-9 pressed
self._current_rot = self._start_rot #current rotation state
self._face_polys = None
@@ -337,7 +338,7 @@ def rotate(self, rot):
self._current_rot = self._current_rot * rot
def rotate_face(self, face, turns=1, layer=0, steps=5):
- if turns != 0:
+ if not np.allclose(turns, 0):
for i in range(steps):
self.cube.rotate_face(face, turns * 1. / steps,
layer=layer)
@@ -359,7 +360,8 @@ def _key_press(self, event):
"""Handler for key press events"""
if event.key == 'shift':
self._shift = True
-
+ elif event.key.isdigit():
+ self._digit_flags[int(event.key)] = 1
elif event.key == 'right':
if self._shift:
ax_LR = self._ax_LR_alt
@@ -385,14 +387,21 @@ def _key_press(self, event):
direction = -1
else:
direction = 1
- self.rotate_face(event.key.upper(), direction)
+
+ if np.any(self._digit_flags[:N]):
+ for d in np.arange(N)[self._digit_flags[:N]]:
+ self.rotate_face(event.key.upper(), direction, layer=d)
+ else:
+ self.rotate_face(event.key.upper(), direction)
self._draw_cube()
def _key_release(self, event):
"""Handler for key release event"""
if event.key == 'shift':
self._shift = False
+ elif event.key.isdigit():
+ self._digit_flags[int(event.key)] = 0
def _mouse_press(self, event):
"""Handler for mouse button press"""

0 comments on commit f6eb26a

Please sign in to comment.