Giter VIP home page Giter VIP logo

manim-presentation's Introduction

For an actively developed fork please check out manim-slides!

manim-presentation

Tool for live presentations using manim.

Install

pip install manim-presentation opencv-python

Usage

Use the class Slide as your scenes base class

from manim_presentation import Slide

class Example(Slide):
    def construct(self):
        ...

call self.pause() when you want to pause the playback and wait for an input to continue (check the keybindings)

Wrap a series of animations between self.start_loop() and self.stop_loop() when you want to loop them (until input to continue)

from manim import *
from manim_presentation import Slide

class Example(Slide):
    def construct(self):
        circle = Circle(radius=3, color=BLUE)
        dot = Dot()

        self.play(GrowFromCenter(circle))
        self.pause()

        self.start_loop()
        self.play(MoveAlongPath(dot, circle), run_time=2, rate_func=linear)
        self.end_loop()

        self.play(dot.animate.move_to(ORIGIN))
        self.pause()

        self.wait()

You must end your Slide with a self.play(...) or a self.wait(..)

To start the presentation using Scene1, Scene2 and so on simply run:

manim_presentation Scene1 Scene2...

Keybindings

Default keybindings to control the presentation

Keybinding Action
Right Arrow Continue/Next Slide
Left Arrow Previous Slide
R Re-Animate Current Slide
Spacebar Play/Pause
Q Quit

You can run the configuration wizard with

manim-presentation-wizard

Alternatively you can specify different keybindings creating a file named manim-presentation.json with the keys: QUIT_KEY CONTINUE_KEY BACK_KEY REWIND_KEY and PLAYPAUSE_KEY manim-presentation uses cv2.waitKeyEx() to wait for keypresses

Run Example

Clone this repository

git clone https://github.com/galatolofederico/manim-presentation.git
cd manim-presentation

Create a virtualenv

virtualenv --python=python3.7 env
. ./env/bin/activate

Install manim and manim-presentation

pip install manim manim-presentation opencv-python

Render the example scene

manim -qh example.py

Run the presentation

manim-presentation Example

Contributions and license

The code is released as Free Software under the GNU/GPLv3 license. Copying, adapting and republishing it is not only consent but also encouraged.

For any further question feel free to reach me at [email protected] or on Telegram @galatolo

manim-presentation's People

Contributors

galatolofederico avatar glatteis 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

manim-presentation's Issues

Memory Leak

Hi, I'm pretty sure that manim_presentation has a "memory leak" with regards to cv2. It doesn't unload the non-playing videos? I definitely keeps them in RAM. So it's not really a leak, but if your presentation is in sum bigger than your RAM, you have a problem.

Often occuring "Index out of range" error

Hi, thanks for the cool project! it often occurs that manim_presentation crashes with index out of bounds. For instance, consider this code (sorry it's not so minimal...)

It should stay on the slide with the second graph, but it just skips to the end and then crashes with "index out of bounds".

from manim import *
from manim_presentation import Slide 
red_edge = {
    "stroke_color": RED,
    "buff": 0
}
blue_edge = {
    "stroke_color": BLUE,
    "buff": 0
}
invisible_vertex = {
    "fill_opacity": 0
}
visible_vertex = {
    "fill_color": GREY
}

class ConstraintGraphScene(Slide):
    def construct(self):
        self.construct_vertices()
        self.clear()
        self.construct_latch()
        self.clear()
        self.play(Create(Text("")))
        self.pause()
        self.wait()

    def construct_latch(self):
        edge_config = {
            (2,1): blue_edge,
            (2,3): blue_edge,
            (4,2): blue_edge,
            (3,4): red_edge,
            (3,5): red_edge,
            (6,4): red_edge
        }
        vertex_config = {}
        for i in [1, 5, 6]:
            vertex_config[i] = invisible_vertex
        for i in [2, 3, 4]:
            vertex_config[i] = visible_vertex
        graph = Graph(vertex_config.keys(), edge_config.keys(), vertex_config=vertex_config, edge_config=edge_config, edge_type=Arrow)
        
        graph[1].move_to([-2,0,0])
        graph[2].move_to([-1,0,0])
        graph[3].move_to([0,1,0])
        graph[4].move_to([0,-1,0])
        graph[5].move_to([2,1,0])
        graph[6].move_to([2,-1,0])

        # graph.scale(1)

        self.play(Create(graph))
        self.play(Create(Text("Out A", color=BLACK).next_to(graph[6], RIGHT)))
        self.play(Create(Text("Out B", color=BLACK).next_to(graph[5], RIGHT)))
        self.play(Create(Text("Lock", color=BLACK).next_to(graph[1], LEFT)))
        self.pause()


    def construct_vertices(self):
        vertices = [1, 2, 3, 4]
        edges = [(1,3), (2,3), (3,4)]
        edge_config_and = {
            (1,3): red_edge,
            (2,3): red_edge,
            (3,4): blue_edge
        }
        edge_config_or = {
            (1,3): blue_edge,
            (2,3): blue_edge,
            (3,4): blue_edge
        }
        vertex_config = {
            1: invisible_vertex, 
            2: invisible_vertex,
            3: visible_vertex,
            4: invisible_vertex
        }
        graph_and_vertex = Graph(vertices, edges, edge_config=edge_config_and, vertex_config=vertex_config, edge_type=Arrow)
        graph_or_vertex = Graph(vertices, edges, edge_config=edge_config_or, vertex_config=vertex_config, edge_type=Arrow)
        graph_and_vertex.move_to(LEFT*2)
        graph_or_vertex.next_to(graph_and_vertex, RIGHT)
        graph_and_vertex.default_edge_config = blue_edge
        graph_or_vertex.default_edge_config = blue_edge

        and_vertex_text = Text("And", color=BLACK)
        and_vertex_text.next_to(graph_and_vertex, DOWN)
        or_vertex_text = Text("Or", color=BLACK)
        or_vertex_text.next_to(graph_or_vertex, DOWN)

        self.play(Create(graph_and_vertex))
        self.play(Create(graph_or_vertex))
        self.play(Create(and_vertex_text))
        self.play(Create(or_vertex_text))

        self.pause()

        self.start_loop()
        self.play(graph_and_vertex.animate.remove_edges((3,4)),
        graph_and_vertex.animate.add_edges((4,3), edge_type=Arrow))
        self.play(graph_and_vertex.animate.remove_edges((4,3)),
        graph_and_vertex.animate.add_edges((3,4), edge_type=Arrow))
        # self.play(graph.animate.add_edges((3,4)), edge_config=edge_config)
        self.end_loop()
        self.pause()
        self.wait()


I compiled the project with:

manim -ql constraint_graph_scene.py ConstraintGraphScene
manim_presentation ConstraintGraphScene

Bad quality of presentation with --fullscreen flag

image
I did a comparison about the quality of manim presentation with the --fullscreen flag. In the first picture, I rendererd a manim scene with manim -qh example.py and then ran it with manim_presentation --fullscreen example. As we can see in the 1st picture, the quality is not so high (it's bad as low-quality rendering).

Then, I tried running without --fullscreen, the quality of the scene turn back to high quality (but lost the ability to be fullscreen).
Seems like when doing the full-screen, the presentation has been scaled down to fit the screen, and cause this bad quality.
image

Is there any way to fix this?

Play animation in reverse when pressing back key

When I press the back key, the player jumps to the previous pause in the code. It would be nice to have an option which allow to play the video in reverse to that previous pause.
I had a quick look on the internet, but it does not seems to be trivial to do it with cv2. I suggest it anyway in case of you are in search of new features to implement one day!
Good job tho it works like a charm, thanks for your tool!
(I do not know how to put this as an enhancement instead of an issue ^^)

Is there anyway to control the manim_presentation window size?

Description

manim_presentation works nicely with small size (-ql).

Screenshot from 2021-06-08 20-14-50

But soon, the rendering creates a problem with larger size (-qh) and (-qk). Because some content is not showing for the -qk file due to large size. This also happens with -qh for the bottom area.

Screenshot from 2021-06-08 20-11-41

It will be greater if we have some controlling/resizing system. I have found how to adjust resolution,

import cv2

cap = cv2.VideoCapture(0)

def make_1080p():
    cap.set(3, 1920)
    cap.set(4, 1080)

def make_720p():
    cap.set(3, 1280)
    cap.set(4, 720)

But couldn't manage where to set cap.set(*,*) inside present.py.

Expecting feature

  • Have some controlling/resizing system

Can't run multiple scenes behind each other

Hi, another issue: I can't run multiple scenes behind each other. When I do manim_presentation Scene1 Scene2, manim-presentation crashes with:

    return self.caps[self.current_animation]
IndexError: list index out of range

I will look at the code and see if I can fix it.

Arrow keys not responding - MacBook Pro, German keyboard

When starting a presentation, the arrow keys on my MacBook Pro - Catalina 10.15.6 - 2019 - German Keyboard - are not responding. Spacebar, q and r are working just fine.

I have no idea how to figure out what code my arrow keys have, hence the issue here.

Animations between loops don't show without pauses

Take for example the following, where I commented out self.pause() between the two loops:

from manim import *
from manim_presentation import Slide

class Example(Slide):
    def construct(self):
        circle = Circle(radius=3, color=BLUE)
        dot = Dot()

        self.play(GrowFromCenter(circle))
        self.pause()

        self.start_loop()
        self.play(MoveAlongPath(dot, circle), run_time=2, rate_func=linear)
        self.end_loop()

        self.play(dot.animate.move_to(ORIGIN))
        #self.pause()

        self.play(dot.animate.move_to(RIGHT*3))
        #self.pause()
        
        self.start_loop()
        self.play(MoveAlongPath(dot, circle), run_time=2, rate_func=linear)
        self.end_loop()

        self.play(dot.animate.move_to(ORIGIN))

When I run through the presentation, it skips past the animation of the dot moving to and from the origin and continues to the next loop. The video files for these animations are still in \manim-presentation\presentation\files but the presentation skips from Animation: 1 to Animation: 4.

I cant create my first presentation even though I followed the instructions provided.

I am trying to render my first presentation but I am getting an error that says no config file found. it asks me to use Slide as base class for scene which i am doing as is evident in the following code: P.S i am using manimCE v0.6.0

from manim import *
from mytextemplate import *
from manim_presentation import Slide



class Testing(Slide):
    def construct(self):
        introduction = MyTexTemplate("Introduction",tex_type = "tex",font = "Alegreya-Regular")
        self.add(introduction)
        self.wait(1)
        self.pause()

The introduction variable is created and uses a custom module that I modified to suit my needs. Following is the error code after the using manim_presentation Testing
File "C:\Users\khans\AppData\Local\Programs\Python\Python39\Scripts\manim_presentation-script.py", line 33, in
sys.exit(load_entry_point('manim-presentation==0.1.3', 'console_scripts', 'manim_presentation')())
File "c:\users\khans\appdata\local\programs\python\python39\lib\site-packages\manim_presentation\present.py", line 238, in main
raise Exception(f"File {config_file} does not exist, check the scene name and make sure to use Slide as your scene base class")
Exception: File ./presentation\Testing.json does not exist, check the scene name and make sure to use Slide as your scene base class

Playback speed is differnt for 30 and 60 fps

When I render my presentation at ql, qm and qh (480p15, 720p30 and 1080p60 respectively) and run them with maim-presentation the playback speed is different. Feels like the viewer always plays at 30fps because the 1080p60 version is very slow.

Edit:
This might be caused by limited resources. I'm running everything from within WSL and it looks like open-cv is doing everything on the CPU.

Ask for permission to change license

Hi @galatolofederico, I am the maintainer of Manim Slide.
As a previous fork of your work, it inherited its license.

As I feel that the current licensing is a bit too restrictive, I am asking the following: are you ok if I change the license of Manim Slide to MIT license?

Fullscreen not really fullscreen

And another one: One fullscreen, there's still a small border around the window. This causes weird aliasing effects. Will see if I can fix this as well.

Can I control the slide presentation by tweaking the json file?

Description

I was working with several versions of manim like manim community version (v0.5.0) and 3b1b version. Now, as they create their own partials_movie_files. I want to merge them all and control the presentation.

For this I want to know how to tweak the .json file generated inside the presentation directory. Like according the docs if I create manim presentation from example.py it creates,

{
  "slides": [
    { "type": "slide", "start_animation": 0, "end_animation": 1, "number": 1 },
    { "type": "loop", "start_animation": 1, "end_animation": 2, "number": 2 },
    { "type": "slide", "start_animation": 2, "end_animation": 3, "number": 3 }
  ],
  "files": [
    "./presentation/files/Example/450974505_3492167877_2166804963.mp4",
    "./presentation/files/Example/2788726626_291667631_3144554360.mp4",
    "./presentation/files/Example/2788726626_2464099577_429927831.mp4",
    "./presentation/files/Example/2788726626_1438405273_1585276179.mp4"
  ]
}

I want to know what those parameter means start_animation, end_animation and number.

Expected behavior

I was thinking start_animation and end_animation are the index of partials_movie_files from the values of the files key, is it?

Suppose I paced some partials_movie_files inside presentation/files/Example directory, then I tweak the .json:

{
  "slides": [
    { "type": "slide", "start_animation": 0, "end_animation": 1, "number": 1 },
    { "type": "loop", "start_animation": 1, "end_animation": 2, "number": 2 },
    { "type": "slide", "start_animation": 2, "end_animation": 3, "number": 3 },
    { "type": "loop", "start_animation": 3, "end_animation": 4, "number": 4 },
    { "type": "slide", "start_animation": 4, "end_animation": 5, "number": 5 }
  ],
  "files": [
    "./presentation/files/Example/450974505_3492167877_2166804963.mp4",
    "./presentation/files/Example/2788726626_291667631_3144554360.mp4",
    "./presentation/files/Example/2788726626_2464099577_429927831.mp4",
    "./presentation/files/Example/2788726626_1438405273_1585276179.mp4",
    "./presentation/files/Example/new_video_01.mp4",
    "./presentation/files/Example/new_video_02.mp4",
  ]
}

But it wasn't showing the desire slide-presentation.

Unable to use arrow keys

I followed all the instructions on the readme, and everything seems to be working fine, all keybinds are okay, space, R, Q, all of them except the arrow keys. Is this a problem of the module or is this unrelated at all?
Additional Info: I'm using Windows 10 64x

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.