wampycakes / manim-rubikscube Goto Github PK
View Code? Open in Web Editor NEWA Manim implementation of the classic Rubik's Cube
License: MIT License
A Manim implementation of the classic Rubik's Cube
License: MIT License
Would you mind sharing the code you used to produce the cube's look from the video? They're really nice!
Without changing any of the code, when we run the basic examples from the plugin documentation, it produces the output without any error. However, every time the cube is placed on the lower-left corner of the screen, and some parts of it are even not inside the screen. I tried to scale it and rotate it to get it in the center, but I failed. Also, when I start camera rotation around the cube, the axis of rotation doesn't go through the cube. It goes outside the cube. So instead of a smooth cube rotation, I am getting a Rubik's cube following a circular horizontal loop.
When the cube is rotated so that it's not axis-aligned, CubeMove throws a KeyError. Example:
from manim import *
from manim_rubikscube import *
class RubiksCubeBug(ThreeDScene):
def construct(self):
cube = RubiksCube()
cube.rotate(axis=[1, 1, 1], angle=PI)
self.add(cube)
self.play(CubeMove(cube, "F"))
self.wait(1)
This gives me:
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ │
│ /usr/local/lib/python3.9/site-packages/manim/cli/render/commands.py:139 in render │
│ │
│ 136 │ │ for SceneClass in scene_classes_from_file(file): │
│ 137 │ │ │ try: │
│ 138 │ │ │ │ scene = SceneClass() │
│ ❱ 139 │ │ │ │ scene.render() │
│ 140 │ │ │ except Exception: │
│ 141 │ │ │ │ error_console.print_exception() │
│ 142 │ │ │ │ sys.exit(1) │
│ /usr/local/lib/python3.9/site-packages/manim/scene/scene.py:213 in render │
│ │
│ 210 │ │ """ │
│ 211 │ │ self.setup() │
│ 212 │ │ try: │
│ ❱ 213 │ │ │ self.construct() │
│ 214 │ │ except EndSceneEarlyException: │
│ 215 │ │ │ pass │
│ 216 │ │ except RerunSceneException as e: │
│ │
│ /Users/vaclav/prog/rubiks-cube-video/cube_bug.py:11 in construct │
│ │
│ 8 │ │ cube.rotate(axis=[1, 1, 1], angle=PI) │
│ 9 │ │ self.add(cube) │
│ 10 │ │ self.play(CubeMove(cube, "F")) │
│ ❱ 11 │ │ self.wait(1) │
│ 12 │
│ │
│ /usr/local/lib/python3.9/site-packages/manim/scene/scene.py:888 in play │
│ │
│ 885 │ │ │ return np.max([animation.run_time for animation in animations]) │
│ 886 │ │
│ 887 │ def play(self, *args, **kwargs): │
│ ❱ 888 │ │ self.renderer.play(self, *args, **kwargs) │
│ 889 │ │
│ 890 │ def wait(self, duration=DEFAULT_WAIT_TIME, stop_condition=None): │
│ 891 │ │ self.play(Wait(run_time=duration, stop_condition=stop_condition)) │
│ │
│ /usr/local/lib/python3.9/site-packages/manim/renderer/cairo_renderer.py:134 in play │
│ │
│ 131 │ │ │ # In this case, as there is only a wait, it will be the length of the wait. │
│ 132 │ │ │ self.freeze_current_frame(scene.duration) │
│ 133 │ │ else: │
│ ❱ 134 │ │ │ scene.play_internal() │
│ 135 │ │ self.file_writer.end_animation(not self.skip_animations) │
│ 136 │ │ │
│ 137 │ │ self.num_plays += 1 │
│ │
│ /usr/local/lib/python3.9/site-packages/manim/scene/scene.py:999 in play_internal │
│ │
│ 996 │ │ │ │ break │
│ 997 │ │ │
│ 998 │ │ for animation in self.animations: │
│ ❱ 999 │ │ │ animation.finish() │
│ 1000 │ │ │ animation.clean_up_from_scene(self) │
│ 1001 │ │ if not self.renderer.skip_animations: │
│ 1002 │ │ │ self.update_mobjects(0) │
│ │
│ /usr/local/lib/python3.9/site-packages/manim_rubikscube/cube_animations.py:31 in finish │
│ │
│ 28 │ │
│ 29 │ def finish(self): │
│ 30 │ │ super().finish() │
│ ❱ 31 │ │ self.mobject.adjust_indices(self.mobject.get_face(self.face[0], False)) │
│ │
│ /usr/local/lib/python3.9/site-packages/manim_rubikscube/cube.py:117 in adjust_indices │
│ │
│ 114 │ │
│ 115 │ def adjust_indices(self, cubies): │
│ 116 │ │ for c in cubies.flatten(): │
│ ❱ 117 │ │ │ loc = self.indices[c.get_rounded_center()] │
│ 118 │ │ │ self.cubies[loc[0], loc[1], loc[2]] = c │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
KeyError: (0.0, 1.4, -0.0)
I am using Manim Community v0.11.0, manim-rubikscube v0.1.0.
Hey there, I really appreciate your work! At the moment OpenGL does support 3D scenes quite effectively so I was wondering if there's going to be OpenGL support any time soon. Thanks!
Whilst performing a clean install of the latest versions of manim-rubikscube (v0.1.0)
and manim (v0.15.2)
in a new python environment, manim-rubikscube
wouldn't even execute returning this error message:
Traceback (most recent call last):
File "/home/grongo/manim/bin/manim-rubikscube", line 5, in <module>
from manim_rubikscube.__main__ import main
File "/home/grongo/manim/lib/python3.10/site-packages/manim_rubikscube/__init__.py", line 1, in <module>
from .cube import *
File "/home/grongo/manim/lib/python3.10/site-packages/manim_rubikscube/cube.py", line 5, in <module>
from .cubie import Cubie
File "/home/grongo/manim/lib/python3.10/site-packages/manim_rubikscube/cubie.py", line 5, in <module>
from manim.mobject.geometry import Square
ImportError: cannot import name 'Square' from 'manim.mobject.geometry' (/home/grongo/manim/lib/python3.10/site-packages/manim/mobject/geometry/__init__.py)
Therefore, I checked out the documentation for the Square
attribute, revealing that it is no longer in manim.mobject.geometry
but is now in manim.mobject.geometry.polygram
.
This issue is fixed by replacing in the cubie.py
file manim.mobject.geometry
with manim.mobject.geometry.polygram
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.