twisting a rubiks cube example
0
fork

Configure Feed

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

Initialized commit

Shwetha f4e29c9b

+137
+11
README.md
··· 1 + # Rubiks Cube 2 + 3 + I was working on this project for a research project and needed to make the rubiks cube from scratch based on our groups numbers and research as well. 4 + 5 + Here is what the final output looked like: 6 + 7 + 8 + 9 + [Twitter Link I posted]() 10 + 11 +
+39
rubiks_model.obj
··· 1 + # Blender v2.91.0 Beta OBJ File: '' 2 + # www.blender.org 3 + mtllib cube.mtl 4 + v 1.000000 1.000000 -1.000000 5 + v 1.000000 -1.000000 -1.000000 6 + v 1.000000 1.000000 1.000000 7 + v 1.000000 -1.000000 1.000000 8 + v -1.000000 1.000000 -1.000000 9 + v -1.000000 -1.000000 -1.000000 10 + v -1.000000 1.000000 1.000000 11 + v -1.000000 -1.000000 1.000000 12 + vt 0.625000 0.500000 13 + vt 0.875000 0.500000 14 + vt 0.875000 0.750000 15 + vt 0.625000 0.750000 16 + vt 0.375000 0.750000 17 + vt 0.625000 1.000000 18 + vt 0.375000 1.000000 19 + vt 0.375000 0.000000 20 + vt 0.625000 0.000000 21 + vt 0.625000 0.250000 22 + vt 0.375000 0.250000 23 + vt 0.125000 0.500000 24 + vt 0.375000 0.500000 25 + vt 0.125000 0.750000 26 + vn 0.0000 1.0000 0.0000 27 + vn 0.0000 0.0000 1.0000 28 + vn -1.0000 0.0000 0.0000 29 + vn 0.0000 -1.0000 0.0000 30 + vn 1.0000 0.0000 0.0000 31 + vn 0.0000 0.0000 -1.0000 32 + usemtl Material 33 + s off 34 + f 1/1/1 5/2/1 7/3/1 3/4/1 35 + f 4/5/2 3/4/2 7/6/2 8/7/2 36 + f 8/8/3 7/9/3 5/10/3 6/11/3 37 + f 6/12/4 2/13/4 4/5/4 8/14/4 38 + f 2/13/5 1/1/5 3/4/5 4/5/5 39 + f 6/11/6 5/10/6 1/1/6 2/13/6
rubikscube.png

This is a binary file and will not be displayed.

+87
rubikswithatwist.py
··· 1 + from ursina import * 2 + 3 + from itertools import product 4 + 5 + 6 + 7 + def parent_child(axel, layer): 8 + 9 + for c in cube: 10 + 11 + c.position, c.rotation = round(c.world_position,1), c.world_rotation 12 + 13 + c.parent = scene 14 + 15 + center.rotation = 0 16 + 17 + for c in cube: 18 + 19 + if eval(f'c.position.z{axel}') == layer: 20 + 21 + c.parent = center 22 + 23 + def input(key): 24 + 25 + if key not in rot_dict: return 26 + 27 + axel, layer, angle = rot_dict[key] 28 + 29 + parent_child(axel, layer) 30 + 31 + shift = held_keys['shift'] 32 + 33 + eval(f'center.animate_rotation_{axel}({-angle if shift else angle}, duration = 0.5)') 34 + 35 + 36 + 37 + 38 + 39 + app = Ursina() 40 + 41 + window.borderless = False 42 + 43 + window.size = (800, 800) 44 + 45 + window.position = (2000, 200) 46 + 47 + EditorCamera() 48 + 49 + 50 + 51 + center = Entity() 52 + 53 + 54 + 55 + rot_dict = {'u': ['y', 1, 90], 'e': ['y', 0, -90], 'd': ['y', -1, -90], 56 + 57 + 'l': ['x', -1, -90], 'm': ['x', 0, -90], 'r': ['x', 1, 90], 58 + 59 + 'f': ['z', -1, 90], 's': ['z', 0, 90], 'b': ['z', 1, -90]} 60 + 61 + 62 + 63 + cube = [] 64 + 65 + for pos in product((-1,0,1), repeat=3): 66 + 67 + cube.append(Entity(model='rubiks_model.obj', texture='rubikscube.png', 68 + 69 + position=pos, scale=0.5)) 70 + 71 + #print(pos) 72 + 73 + #checked that it worked 74 + 75 + 76 + 77 + app.run() 78 + 79 + ## the pos in product the above does the same as below - 80 + 81 + #for x in range(-1,2): 82 + 83 + # for y in range(-1,2): 84 + 85 + # for z in range(-1,2): 86 + 87 + # pos = (x,y,z)