twisting a rubiks cube example
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

RUBIKSFRESH done live

+47 -21
+30
RUBIXFRESH.py
··· 1 + from itertools import product 2 + from ursina import * 3 + 4 + app = Ursina() 5 + window.borderless = False 6 + window.borderless = False 7 + window.size = (800, 800) 8 + window.position = (2000, 200) 9 + EditorCamera() 10 + 11 + cube = [] 12 + for pos in product((-1,0,1), repeat=3): 13 + print(pos) 14 + 15 + 16 + rot_dict = {'u': ['y', 1, 90], 'e': ['y', 0, -90], 'd': ['y', -1, -90], 17 + 18 + 'l': ['x', -1, -90], 'm': ['x', 0, -90], 'r': ['x', 1, 90], 19 + 20 + 'f': ['z', -1, 90], 's': ['z', 0, 90], 'b': ['z', 1, -90]} 21 + 22 + 23 + 24 + # rotating the cube 25 + for c in cube: 26 + c.rotation, c.position = round(c.world) 27 + 28 + def input(key): 29 + # 30 + app.run()
+17 -21
rubiks-indented.py
··· 1 - #indented properly now 2 - from ursina import * 1 + # indented properly now 2 + # via LM-studio 3 3 from itertools import product 4 + 5 + from ursina import * 4 6 5 7 6 8 def parent_child(axel, layer): 7 9 # Iterate over existing cubes to round their world position/rotation 8 10 for c in cube: 9 11 c.position, c.rotation = round(c.world_position, 1), c.world_rotation 10 - 12 + 11 13 # Detach all cubes from their current parents (default is scene or previous hierarchy) 12 14 c.parent = scene 13 15 center.rotation = 0 ··· 25 27 axle, layer, angle = rot_dict[key] 26 28 parent_child(axle, layer) 27 29 28 - shift = held_keys['shift'] 29 - 30 + shift = held_keys["shift"] 31 + 30 32 # Construct the animation command dynamically 31 33 anim_cmd = f"center.animate_rotation_{axle}" 32 34 eval(f"{anim_cmd}({-angle if shift else angle}, duration=0.5)") ··· 42 44 center = Entity() 43 45 44 46 rot_dict = { 45 - 'u': ['y', 1, 90], # Up 46 - 'e': ['y', 0, -90], # Even (middle layer Y?) 47 - 'd': ['y', -1, -90], # Down 48 - 49 - 'l': ['x', -1, -90], # Left 50 - 'm': ['x', 0, -90], # Middle layer X? 51 - 'r': ['x', 1, 90], # Right 52 - 53 - 'f': ['z', -1, 90], # Front 54 - 's': ['z', 0, 90], # Back/Side? 55 - 'b': ['z', 1, -90] # Back 47 + "u": ["y", 1, 90], # Up 48 + "e": ["y", 0, -90], # Even (middle layer Y?) 49 + "d": ["y", -1, -90], # Down 50 + "l": ["x", -1, -90], # Left 51 + "m": ["x", 0, -90], # Middle layer X? 52 + "r": ["x", 1, 90], # Right 53 + "f": ["z", -1, 90], # Front 54 + "s": ["z", 0, 90], # Back/Side? 55 + "b": ["z", 1, -90], # Back 56 56 } 57 57 58 58 cube = [] 59 59 for pos in product((-1, 0, 1), repeat=3): 60 60 cube.append( 61 61 Entity( 62 - model='rubiks_model.obj', 63 - texture='rubikscube.png', 64 - position=pos, 65 - scale=0.5 62 + model="rubiks_model.obj", texture="rubikscube.png", position=pos, scale=0.5 66 63 ) 67 64 ) 68 65 # print(pos) # Debugging print (commented out as per your original code) 69 66 # checked that it worked 70 67 71 68 app.run() 72 -