twisting a rubiks cube example
0
fork

Configure Feed

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

testing for interview prep whichever file works

+187
models_compressed/rubiks_model.bam

This is a binary file and will not be displayed.

+72
rubiks-indented.py
··· 1 + #indented properly now 2 + from ursina import * 3 + from itertools import product 4 + 5 + 6 + def parent_child(axel, layer): 7 + # Iterate over existing cubes to round their world position/rotation 8 + for c in cube: 9 + c.position, c.rotation = round(c.world_position, 1), c.world_rotation 10 + 11 + # Detach all cubes from their current parents (default is scene or previous hierarchy) 12 + c.parent = scene 13 + center.rotation = 0 14 + 15 + # Re-parent specific layers to the 'center' entity 16 + for c in cube: 17 + if eval(f"c.position.{axel}") == layer: 18 + c.parent = center 19 + 20 + 21 + def input(key): 22 + if key not in rot_dict: 23 + return 24 + 25 + axle, layer, angle = rot_dict[key] 26 + parent_child(axle, layer) 27 + 28 + shift = held_keys['shift'] 29 + 30 + # Construct the animation command dynamically 31 + anim_cmd = f"center.animate_rotation_{axle}" 32 + eval(f"{anim_cmd}({-angle if shift else angle}, duration=0.5)") 33 + 34 + 35 + app = Ursina() 36 + 37 + window.borderless = False 38 + window.size = (800, 800) 39 + window.position = (2000, 200) 40 + EditorCamera() 41 + 42 + center = Entity() 43 + 44 + 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 56 + } 57 + 58 + cube = [] 59 + for pos in product((-1, 0, 1), repeat=3): 60 + cube.append( 61 + Entity( 62 + model='rubiks_model.obj', 63 + texture='rubikscube.png', 64 + position=pos, 65 + scale=0.5 66 + ) 67 + ) 68 + # print(pos) # Debugging print (commented out as per your original code) 69 + # checked that it worked 70 + 71 + app.run() 72 +
+53
rubiks_OOJ.py
··· 1 + 2 + ''' 3 + 4 + makin a rubix cube simulation 5 + the OOJ way!! 6 + 7 + ''' 8 + ### trying it the ObJeCtEd ORiEnTed method way 9 + # because that is coOL 10 + from ursina import * 11 + import ursina as urs 12 + from ursina.prefabs import Button 13 + 14 + x = Button() 15 + 16 + #create a window 17 + app = urs.Ursina() 18 + 19 + 20 + # ok so now you have a window you must make en Entity 21 + # Entities area thing you place in the world 22 + # the first parameter is the model of the Entity 23 + # called 'cube' 24 + # the next parameters are the model's color 25 + # 26 + 27 + player = urs.Entity(model='cube', color=urs.color.orange, scale_y=2) 28 + 29 + 30 + 31 + # creating a function called update 32 + 33 + def update(): 34 + player.x += urs.held_keys['d'] * urs.time.daylight 35 + player.x -= urs.held_keys['a'] * urs.time.daylight 36 + return 37 + 38 + 39 + # this makes the player aka the cube move left or right! 40 + # # based on input 41 + # # 0 means not pressed and 1 means pressed 42 + # # player will move the same speed regardless of how gast the game runs 43 + def my_input(key): 44 + if key == 'space': 45 + player.y += 1 46 + urs.invoke(setattr, player, 'y', player.y, delay =0.2) 47 + 48 + # start running the game ! 49 + app.run() 50 + # 51 + # 52 + # 53 + #
+62
rubikszed.py
··· 1 + # 1. Explicit Imports (Replaced 'from ursina import *') 2 + from ursina import * 3 + from itertools import product 4 + 5 + 6 + def parent_child(axel, layer): 7 + #Iterate over existing cubes to round their world position/rotation 8 + for c in cube: 9 + c.position, c.rotation = round(c.world_position, 1), c.world_rotation 10 + 11 + # Detach all cubes from their current parents (default is scene or previous hierarchy) 12 + c.parent = scene 13 + center.rotation = 0 14 + 15 + # Re-parent specific layers to the 'center' entity 16 + for c in cube: 17 + if eval(f"c.position.{axel}") == layer: 18 + c.parent = center 19 + 20 + 21 + def input(key): 22 + if key not in rot_dict: 23 + return 24 + 25 + axle, layer, angle = rot_dict[key] 26 + parent_child(axle, layer) 27 + 28 + shift = held_keys["shift"] 29 + 30 + # Construct the animation command dynamically 31 + anim_cmd = f"center.animate_rotation_{axle}" 32 + eval(f"{anim_cmd}({-angle if shift else angle}, duration=0.5)") 33 + 34 + 35 + # Initialize App 36 + app = Ursina() 37 + window.borderless = False 38 + window.size = (800, 800) 39 + window.position = (2000, 200) 40 + EditorCamera() 41 + 42 + center = Entity() 43 + 44 + 45 + rot_dict = {'u': ['y', 1, 90], 'e': ['y', 0, -90], 'd': ['y', -1, -90], 46 + 47 + 'l': ['x', -1, -90], 'm': ['x', 0, -90], 'r': ['x', 1, 90], 48 + 49 + 'f': ['z', -1, 90], 's': ['z', 0, 90], 'b': ['z', 1, -90]} 50 + 51 + 52 + 53 + cube = [] 54 + for pos in product((-1, 0, 1), repeat=3): 55 + cube.append( 56 + Entity( 57 + model="models_compressed/rubiks_model.bam", texture="rubikscube.png", position=pos, scale=0.5 58 + ) 59 + ) 60 + 61 + app.run() 62 +