-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Open
Description
Description of bug / unexpected behavior
The Code lines height and center are offset when the code is indented.
Expected behavior
Adding rects as code coverage, the geometry of individual lines is not correctly calculated when they're indented.
How to reproduce the issue
Code for reproducing the problem
from manim import *
class CoverageWhatIsCoverage(Scene):
def construct(self):
js_code = '''function greet(name) {
console.log(name);
}
greet("World");'''
code = Code(
code_string=js_code,
language="javascript",
add_line_numbers=False,
background_config={"stroke_color": WHITE},
paragraph_config={"font": "Source Code Pro"},
)
code.to_edge(LEFT)
self.play(Write(code), run_time=1)
self.wait(1)
lines = js_code.splitlines()
for idx, content in enumerate(lines):
if not content.strip():
continue
line = code.code_lines[idx]
adjustment = 0
center = line.get_center()
# HACK: Adjust the rectangle position based on the content
# a bug in manim causes the rectangle to be slightly off
# remove this if to reproduce, with it it visually fixes it for me
if content.startswith(" "):
adjustment = line.get_height() * 0.4
center += DOWN * 0.11
rect = Rectangle(
width=100,
height=line.get_height() - adjustment,
fill_color=GREEN,
fill_opacity=0.2,
stroke_width=0,
)
rect.move_to(center)
self.play(FadeIn(rect), run_time=0.1)
self.wait(5)
Additional media files
Logs
Terminal output
Manim Community v0.19.0
[06/17/25 17:23:28] INFO Animation 0 : Using cached data (hash : 3445125925_411229538_223132457) cairo_renderer.py:89
INFO Animation 1 : Using cached data (hash : 1025971384_1839128356_1807648307) cairo_renderer.py:89
/home/dkarlovi/Development/Sigwin/qpr-manim/scene/01_coverage_what_is_coverage/__init__.py:38: DeprecationWarning: This method is not guaranteed to stay around. Please prefer getting the attribute normally.
height=line.get_height() - adjustment,
INFO Animation 2 : Using cached data (hash : 1025971384_2487912028_3294283735) cairo_renderer.py:89
INFO Animation 3 : Partial movie file written in scene_file_writer.py:588
'/home/dkarlovi/Development/Sigwin/qpr-manim/media/videos/__init__/1080p30/part
ial_movie_files/CoverageWhatIsCoverage/1025971384_1971682402_2238778438.mp4'
INFO Animation 4 : Partial movie file written in scene_file_writer.py:588
'/home/dkarlovi/Development/Sigwin/qpr-manim/media/videos/__init__/1080p30/part
ial_movie_files/CoverageWhatIsCoverage/1025971384_4026521126_748586998.mp4'
INFO Animation 5 : Partial movie file written in scene_file_writer.py:588
'/home/dkarlovi/Development/Sigwin/qpr-manim/media/videos/__init__/1080p30/part
ial_movie_files/CoverageWhatIsCoverage/1025971384_3062402538_251290373.mp4'
[06/17/25 17:23:30] INFO Animation 6 : Partial movie file written in scene_file_writer.py:588
'/home/dkarlovi/Development/Sigwin/qpr-manim/media/videos/__init__/1080p30/part
ial_movie_files/CoverageWhatIsCoverage/1025971384_2015106682_3470819579.mp4'
INFO Combining to Movie file. scene_file_writer.py:739
INFO scene_file_writer.py:886
File ready at
'/home/dkarlovi/Development/Sigwin/qpr-manim/media/videos/__init__/1080p30/Cove
rageWhatIsCoverage.mp4'
INFO The partial movie directory is full (> 100 files). Therefore, manim has removed scene_file_writer.py:856
the 4 oldest file(s). You can change this behaviour by changing
max_files_cached in config.
INFO Rendered CoverageWhatIsCoverage scene.py:255
Played 7 animations
qpr-manim-py3.13dkarlovi@Vito:~/Development/Sigwin/qpr-manim$ make render/scene/01_coverage_what_is_coverage/hd@30
Manim Community v0.19.0
/home/dkarlovi/Development/Sigwin/qpr-manim/scene/01_coverage_what_is_coverage/__init__.py:38: DeprecationWarning: This method is not guaranteed to stay around. Please prefer getting the attribute normally.
height=line.get_height() - adjustment,
[06/17/25 17:25:11] INFO scene_file_writer.py:886
File ready at
'/home/dkarlovi/Development/Sigwin/qpr-manim/media/images/__init__/CoverageWhat
IsCoverage_ManimCE_v0.19.0.png'
INFO Rendered CoverageWhatIsCoverage scene.py:255
Played 7 animations
System specifications
System Details
- OS Windows 11 with WSL, Fedora 32
- RAM: 64GB
- Python version (
python/py/python3 --version
): 3.13.3 - Installed modules (provide output from
pip list
):
audioop-lts 0.2.1 LTS Port of Python audioop
av 13.1.0 Pythonic bindings for FFmpeg's libraries.
beautifulsoup4 4.13.4 Screen-scraping library
click 8.2.1 Composable command line interface toolkit
cloup 3.0.7 Adds features to Click: option groups, constraints, subcommand sections and help themes.
decorator 5.2.1 Decorators for Humans
glcontext 3.0.0 Portable Headless OpenGL Context
iniconfig 2.1.0 brain-dead simple config-ini parsing
isosurfaces 0.1.2 Construct isolines/isosurfaces over a 2D/3D scalar field defined by a function (not a uniform g...
manim 0.19.0 204e44a Animation engine for explanatory math videos.
manimpango 0.6.0 Bindings for Pango for using with Manim.
mapbox-earcut 1.0.3 Python bindings for the mapbox earcut C++ polygon triangulation library
markdown-it-py 3.0.0 Python port of markdown-it. Markdown parsing, done right!
mdurl 0.1.2 Markdown URL utilities
moderngl 5.12.0 ModernGL: High performance rendering for Python 3
moderngl-window 3.1.1 A cross platform helper library for ModernGL making window creation and resource loading simple
networkx 3.5 Python package for creating and manipulating graphs and networks
nodeenv 1.9.1 Node.js virtual environment builder
numpy 2.3.0 Fundamental package for array computing in Python
packaging 25.0 Core utilities for Python packages
pillow 11.2.1 Python Imaging Library (Fork)
pluggy 1.6.0 plugin and hook calling mechanisms for python
pycairo 1.28.0 Python interface for cairo
pydub 0.25.1 Manipulate audio with an simple and easy high level interface
pyglet 2.1.6 pyglet is a cross-platform games and multimedia package.
pyglm 2.8.2 OpenGL Mathematics library for Python
pygments 2.19.1 Pygments is a syntax highlighting package written in Python.
pyright 1.1.402 Command line wrapper for pyright
pytest 8.4.0 pytest: simple powerful testing with Python
rich 14.0.0 Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal
ruff 0.11.13 An extremely fast Python linter and code formatter, written in Rust.
scipy 1.15.3 Fundamental algorithms for scientific computing in Python
screeninfo 0.8.1 Fetch location and size of physical screens.
skia-pathops 0.8.0.post2 Python access to operations on paths using the Skia library
soupsieve 2.7 A modern CSS selector implementation for Beautiful Soup.
srt 3.5.3 A tiny library for parsing, modifying, and composing SRT files.
svgelements 1.9.6 Svg Elements Parsing
tqdm 4.67.1 Fast, Extensible Progress Meter
typing-extensions 4.14.0 Backported and Experimental Type Hints for Python 3.9+
watchdog 6.0.0 Filesystem events monitoring
LaTeX details
- LaTeX distribution (e.g. TeX Live 2020):
- Installed LaTeX packages:
Additional comments
N/A.
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
🆕 New