GithubHelp home page GithubHelp logo

wampycakes / manim-rubikscube Goto Github PK

View Code? Open in Web Editor NEW
44.0 1.0 6.0 131.71 MB

A Manim implementation of the classic Rubik's Cube

License: MIT License

Python 100.00%
manim-rubikscube rubikscube-plugin rubik-cube cubies manim rubikscube solver animate animations

manim-rubikscube's Introduction

Manim RubiksCube

This plugin for Manim Community provides an implementation of the classic Rubik's Cube.

Installation

This plugin is available on PyPi. Usage of this plugin assumes that Python and Manim are both correctly installed. Manim is listed as a dependency, but no version is specified. This is because the plugin will work with any version of Manim Community that does not have breaking changes to the plugin. Some releases of this plugin have been tested with certain versions of Manim. To see what versions of Manim are confirmed to be compatible with this plugin (to the best of my testing), see Releases. By no means is this exclusive. Most releases of this plugin will work, more or less, on all versions of Manim Community.

To install the RubiksCube plugin run:

pip install manim-rubikscube

To see what version of manim-rubikscube you are running:

manim-rubikscube

or

pip list

Importing

To use the RubiksCube, you can either:

Once the RubiksCube is imported, you can use the RubiksCube as any other mobject.

Documentation and Examples

Documentation and examples are available here.

License

This plugin is licensed under the MIT license. See the LICENSE file for more information.

manim-rubikscube's People

Contributors

kolibril13 avatar wampycakes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

manim-rubikscube's Issues

Rendering problem

During the rotation, there's a rendering problem as show in the video and picture.

Main.mp4

Square is not an attribute of manim.mobject.geometry anymore.

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.

CubeMove breaks when the cube is rotated

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.

OpenGL Support?

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!

Camera angle problem

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.