Closed
Description
Description of bug / unexpected behavior
- The
Rectangle
grid lines don't follow thestroke_color
andstroke_width
arguments. - There is an error of imports when trying to create a
Rectangle
with ay
grid only.
Expected behavior
- The
Rectangle
grid lines should follow thestroke_color
andstroke_width
arguments. - There should be no error of imports when trying to create a
Rectangle
with ay
grid only.
How to reproduce the issue
Code for reproducing the problem
from manim import *
class GridYStepImportLine(Scene):
"""The `rect2` construction should not raise an error."""
def construct(self):
rect1 = Rectangle(grid_xstep=0.2)
rect2 = Rectangle(grid_ystep=0.2)
# NameError: free variable 'Line' referenced before assignment in
# enclosing scope
self.add(VGroup(rect1, rect2).arrange(DOWN))
class RectangleGridProperties(Scene):
"""Both `rect1` and `rect2` should be similar.
But only `rect2` is as expected here."""
def construct(self):
grid_kwargs = dict(grid_xstep=0.8, grid_ystep=0.5)
stroke_kwargs = dict(width=10, color=BLUE)
stroke_kwargs_full = {f"stroke_{k}": v for k, v in stroke_kwargs.items()}
rect1 = Rectangle(**stroke_kwargs_full, **grid_kwargs)
rect2 = Rectangle(**grid_kwargs)
rect2.set_stroke(**stroke_kwargs)
self.add(VGroup(rect1, rect2).arrange(DOWN))
Proposed solution
- Pass down
stroke_color
andstroke_width
to theLine
s making the grid - import
Line
also whenxgrid_step is None
Code that resolves the issue
class Rectangle(Polygon):
"""..."""
def __init__(
self,
color: Color = WHITE,
height: float = 2.0,
width: float = 4.0,
grid_xstep: float | None = None,
grid_ystep: float | None = None,
mark_paths_closed: bool = True,
close_new_points: bool = True,
**kwargs,
):
super().__init__(UR, UL, DL, DR, color=color, **kwargs)
self.stretch_to_fit_width(width)
self.stretch_to_fit_height(height)
if (grid_xstep is not None) or (grid_ystep is not None):
from manim.mobject.geometry.line import Line
upper_left = self.get_vertices()[1]
line_kwargs = {"color": color}
line_kwargs.update(
{k: kwargs[k] for k in ["stroke_color", "stroke_width"] if k in kwargs}
)
if grid_xstep is not None:
grid_xstep = abs(grid_xstep)
count = int(width / grid_xstep)
grid = VGroup(
*(
Line(
upper_left + i * grid_xstep * RIGHT,
upper_left + i * grid_xstep * RIGHT + height * DOWN,
**line_kwargs,
)
for i in range(1, count)
)
)
self.add(grid)
if grid_ystep is not None:
grid_ystep = abs(grid_ystep)
count = int(height / grid_ystep)
grid = VGroup(
*(
Line(
upper_left + i * grid_ystep * DOWN,
upper_left + i * grid_ystep * DOWN + width * RIGHT,
**line_kwargs,
)
for i in range(1, count)
)
)
self.add(grid)
Additional media files
System specifications
System Details
- OS: Ubuntu 20.04.5 LTS x86_64
- Python version: Python 3.10.8
- Installed modules (provide output from
pip list
):
# packages in environment at /home/paul/miniconda3/envs/manim-dev:
#
# Name Version Build Channel
_ipython_minor_entry_point 8.7.0 hb6b4a82_0 conda-forge
_libgcc_mutex 0.1 conda_forge conda-forge
_openmp_mutex 4.5 2_gnu conda-forge
alsa-lib 1.2.8 h166bdaf_0 conda-forge
anyio 3.6.2 pyhd8ed1ab_0 conda-forge
aom 3.5.0 h27087fc_0 conda-forge
argon2-cffi 21.3.0 pyhd8ed1ab_0 conda-forge
argon2-cffi-bindings 21.2.0 py310h5764c6d_3 conda-forge
astroid 2.12.13 py310hff52083_0 conda-forge
asttokens 2.2.1 pyhd8ed1ab_0 conda-forge
attr 2.5.1 h166bdaf_1 conda-forge
attrs 22.1.0 pyh71513ae_1 conda-forge
backcall 0.2.0 pyh9f0ad1d_0 conda-forge
backports 1.0 pyhd8ed1ab_3 conda-forge
backports.functools_lru_cache 1.6.4 pyhd8ed1ab_0 conda-forge
beautifulsoup4 4.11.1 pyha770c72_0 conda-forge
black 22.10.0 py310hff52083_2 conda-forge
bleach 5.0.1 pyhd8ed1ab_0 conda-forge
brotlipy 0.7.0 py310h5764c6d_1005 conda-forge
bzip2 1.0.8 h7f98852_4 conda-forge
ca-certificates 2022.12.7 ha878542_0 conda-forge
cachecontrol 0.12.11 pyhd8ed1ab_0 conda-forge
cairo 1.16.0 ha61ee94_1014 conda-forge
certifi 2022.12.7 pyhd8ed1ab_0 conda-forge
cffi 1.15.1 py310h255011f_3 conda-forge
charset-normalizer 2.1.1 pyhd8ed1ab_0 conda-forge
cleo 2.0.1 pyhd8ed1ab_0 conda-forge
click 8.1.3 unix_pyhd8ed1ab_2 conda-forge
click-default-group 1.2.2 pyhd8ed1ab_1 conda-forge
cloup 0.13.1 pyhd8ed1ab_0 conda-forge
colorama 0.4.6 pyhd8ed1ab_0 conda-forge
colour 0.1.5 py_0 conda-forge
comm 0.1.2 pyhd8ed1ab_0 conda-forge
commonmark 0.9.1 py_0 conda-forge
crashtest 0.4.1 pyhd8ed1ab_0 conda-forge
cryptography 38.0.4 py310h600f1e7_0 conda-forge
dataclasses 0.8 pyhc8e2a94_3 conda-forge
dbus 1.13.6 h5008d03_3 conda-forge
debugpy 1.6.4 py310hd8f1fbe_0 conda-forge
decorator 5.1.1 pyhd8ed1ab_0 conda-forge
defusedxml 0.7.1 pyhd8ed1ab_0 conda-forge
dill 0.3.6 pyhd8ed1ab_1 conda-forge
distlib 0.3.6 pyhd8ed1ab_0 conda-forge
dulwich 0.20.50 py310h1fa729e_0 conda-forge
entrypoints 0.4 pyhd8ed1ab_0 conda-forge
executing 1.2.0 pyhd8ed1ab_0 conda-forge
expat 2.5.0 h27087fc_0 conda-forge
ffmpeg 5.1.2 gpl_h8dda1f0_105 conda-forge
fftw 3.3.10 nompi_hf0379b8_106 conda-forge
filelock 3.8.2 pyhd8ed1ab_0 conda-forge
flit-core 3.8.0 pyhd8ed1ab_0 conda-forge
font-ttf-dejavu-sans-mono 2.37 hab24e00_0 conda-forge
font-ttf-inconsolata 3.000 h77eed37_0 conda-forge
font-ttf-source-code-pro 2.038 h77eed37_0 conda-forge
font-ttf-ubuntu 0.83 hab24e00_0 conda-forge
fontconfig 2.14.1 hc2a2eb6_0 conda-forge
fonts-conda-ecosystem 1 0 conda-forge
fonts-conda-forge 1 0 conda-forge
freetype 2.12.1 hca18f0e_1 conda-forge
fribidi 1.0.10 h36c2ea0_0 conda-forge
future 0.18.2 pyhd8ed1ab_6 conda-forge
gettext 0.21.1 h27087fc_0 conda-forge
glcontext 2.3.7 py310hd8f1fbe_0 conda-forge
glib 2.74.1 h6239696_1 conda-forge
glib-tools 2.74.1 h6239696_1 conda-forge
gmp 6.2.1 h58526e2_0 conda-forge
gnutls 3.7.8 hf3e180e_0 conda-forge
graphite2 1.3.13 h58526e2_1001 conda-forge
gst-plugins-base 1.21.2 h3e40eee_0 conda-forge
gstreamer 1.21.2 hd4edc92_0 conda-forge
gstreamer-orc 0.4.33 h166bdaf_0 conda-forge
harfbuzz 6.0.0 h8e241bc_0 conda-forge
html5lib 1.1 pyh9f0ad1d_0 conda-forge
icu 70.1 h27087fc_0 conda-forge
idna 3.4 pyhd8ed1ab_0 conda-forge
importlib-metadata 5.2.0 pyha770c72_0 conda-forge
importlib_metadata 5.2.0 hd8ed1ab_0 conda-forge
importlib_resources 5.10.1 pyhd8ed1ab_0 conda-forge
ipykernel 6.19.3 pyh210e3f2_0 conda-forge
ipython 8.7.0 pyh41d4057_0 conda-forge
ipython_genutils 0.2.0 py_1 conda-forge
ipywidgets 8.0.3 pyhd8ed1ab_0 conda-forge
isort 5.11.3 pyhd8ed1ab_0 conda-forge
isosurfaces 0.1.0 pyhd8ed1ab_0 conda-forge
jack 1.9.21 h583fa2b_2 conda-forge
jaraco.classes 3.2.3 pyhd8ed1ab_0 conda-forge
jedi 0.18.2 pyhd8ed1ab_0 conda-forge
jeepney 0.8.0 pyhd8ed1ab_0 conda-forge
jinja2 3.1.2 pyhd8ed1ab_1 conda-forge
jpeg 9e h166bdaf_2 conda-forge
jsonschema 4.17.3 pyhd8ed1ab_0 conda-forge
jupyter 1.0.0 py310hff52083_8 conda-forge
jupyter_client 7.4.8 pyhd8ed1ab_0 conda-forge
jupyter_console 6.4.4 pyhd8ed1ab_0 conda-forge
jupyter_core 5.1.0 py310hff52083_0 conda-forge
jupyter_events 0.5.0 pyhd8ed1ab_0 conda-forge
jupyter_server 2.0.1 pyhd8ed1ab_0 conda-forge
jupyter_server_terminals 0.4.3 pyhd8ed1ab_0 conda-forge
jupyterlab_pygments 0.2.2 pyhd8ed1ab_0 conda-forge
jupyterlab_widgets 3.0.4 pyhd8ed1ab_0 conda-forge
keyring 23.11.0 py310hff52083_0 conda-forge
keyutils 1.6.1 h166bdaf_0 conda-forge
krb5 1.20.1 h81ceb04_0 conda-forge
lame 3.100 h166bdaf_1003 conda-forge
lazy-object-proxy 1.8.0 py310h5764c6d_0 conda-forge
lcms2 2.14 hfd0df8a_1 conda-forge
ld_impl_linux-64 2.39 hcc3a1bd_1 conda-forge
lerc 4.0.0 h27087fc_0 conda-forge
libblas 3.9.0 16_linux64_openblas conda-forge
libcap 2.66 ha37c62d_0 conda-forge
libcblas 3.9.0 16_linux64_openblas conda-forge
libclang 15.0.6 default_h2e3cab8_0 conda-forge
libclang13 15.0.6 default_h3a83d3e_0 conda-forge
libcups 2.3.3 h36d4200_3 conda-forge
libdb 6.2.32 h9c3ff4c_0 conda-forge
libdeflate 1.14 h166bdaf_0 conda-forge
libdrm 2.4.114 h166bdaf_0 conda-forge
libedit 3.1.20191231 he28a2e2_2 conda-forge
libevent 2.1.10 h28343ad_4 conda-forge
libffi 3.4.2 h7f98852_5 conda-forge
libflac 1.4.2 h27087fc_0 conda-forge
libgcc-ng 12.2.0 h65d4601_19 conda-forge
libgcrypt 1.10.1 h166bdaf_0 conda-forge
libgfortran-ng 12.2.0 h69a702a_19 conda-forge
libgfortran5 12.2.0 h337968e_19 conda-forge
libglib 2.74.1 h606061b_1 conda-forge
libgomp 12.2.0 h65d4601_19 conda-forge
libgpg-error 1.45 hc0c96e0_0 conda-forge
libiconv 1.17 h166bdaf_0 conda-forge
libidn2 2.3.4 h166bdaf_0 conda-forge
liblapack 3.9.0 16_linux64_openblas conda-forge
libllvm15 15.0.6 h63197d8_0 conda-forge
libnsl 2.0.0 h7f98852_0 conda-forge
libogg 1.3.4 h7f98852_1 conda-forge
libopenblas 0.3.21 pthreads_h78a6416_3 conda-forge
libopus 1.3.1 h7f98852_1 conda-forge
libpciaccess 0.17 h166bdaf_0 conda-forge
libpng 1.6.39 h753d276_0 conda-forge
libpq 15.1 hb675445_2 conda-forge
libsndfile 1.1.0 hcb278e6_1 conda-forge
libsodium 1.0.18 h36c2ea0_1 conda-forge
libsqlite 3.40.0 h753d276_0 conda-forge
libstdcxx-ng 12.2.0 h46fd767_19 conda-forge
libsystemd0 252 h2a991cd_0 conda-forge
libtasn1 4.19.0 h166bdaf_0 conda-forge
libtiff 4.5.0 h82bc61c_0 conda-forge
libtool 2.4.6 h9c3ff4c_1008 conda-forge
libudev1 252 h166bdaf_0 conda-forge
libunistring 0.9.10 h7f98852_0 conda-forge
libuuid 2.32.1 h7f98852_1000 conda-forge
libva 2.16.0 h166bdaf_0 conda-forge
libvorbis 1.3.7 h9c3ff4c_0 conda-forge
libvpx 1.11.0 h9c3ff4c_3 conda-forge
libwebp-base 1.2.4 h166bdaf_0 conda-forge
libxcb 1.13 h7f98852_1004 conda-forge
libxkbcommon 1.0.3 he3ba5ed_0 conda-forge
libxml2 2.10.3 h7463322_0 conda-forge
libzlib 1.2.13 h166bdaf_4 conda-forge
lockfile 0.12.2 py_1 conda-forge
lz4-c 1.9.3 h9c3ff4c_1 conda-forge
manim 0.17.1 pyhd8ed1ab_0 conda-forge
manimpango 0.4.3 py310h6eb65c7_0 conda-forge
mapbox_earcut 1.0.0 py310hbf28c38_5 conda-forge
markupsafe 2.1.1 py310h5764c6d_2 conda-forge
matplotlib-inline 0.1.6 pyhd8ed1ab_0 conda-forge
mccabe 0.7.0 pyhd8ed1ab_0 conda-forge
mistune 2.0.4 pyhd8ed1ab_0 conda-forge
moderngl 5.7.4 py310h9b08913_0 conda-forge
moderngl-window 2.4.1 pyhd8ed1ab_0 conda-forge
more-itertools 9.0.0 pyhd8ed1ab_0 conda-forge
mpg123 1.31.1 h27087fc_0 conda-forge
msgpack-python 1.0.4 py310hbf28c38_1 conda-forge
multipledispatch 0.6.0 py_0 conda-forge
mypy_extensions 0.4.3 py310hff52083_6 conda-forge
mysql-common 8.0.31 h26416b9_0 conda-forge
mysql-libs 8.0.31 hbc51c84_0 conda-forge
nbclassic 0.4.8 pyhd8ed1ab_0 conda-forge
nbclient 0.7.2 pyhd8ed1ab_0 conda-forge
nbconvert 7.2.7 pyhd8ed1ab_0 conda-forge
nbconvert-core 7.2.7 pyhd8ed1ab_0 conda-forge
nbconvert-pandoc 7.2.7 pyhd8ed1ab_0 conda-forge
nbformat 5.7.1 pyhd8ed1ab_0 conda-forge
ncurses 6.3 h27087fc_1 conda-forge
nest-asyncio 1.5.6 pyhd8ed1ab_0 conda-forge
nettle 3.8.1 hc379101_1 conda-forge
networkx 2.8.8 pyhd8ed1ab_0 conda-forge
notebook 6.5.2 pyha770c72_1 conda-forge
notebook-shim 0.2.2 pyhd8ed1ab_0 conda-forge
nspr 4.35 h27087fc_0 conda-forge
nss 3.82 he02c5a1_0 conda-forge
numpy 1.24.0 py310h08bbf29_0 conda-forge
openh264 2.3.1 h27087fc_1 conda-forge
openjpeg 2.5.0 hfec8fc6_2 conda-forge
openssl 3.0.7 h0b41bf4_1 conda-forge
p11-kit 0.24.1 hc5aa10d_0 conda-forge
packaging 22.0 pyhd8ed1ab_0 conda-forge
pandoc 2.19.2 h32600fe_1 conda-forge
pandocfilters 1.5.0 pyhd8ed1ab_0 conda-forge
pango 1.50.12 hd33c08f_1 conda-forge
parso 0.8.3 pyhd8ed1ab_0 conda-forge
pathspec 0.10.3 pyhd8ed1ab_0 conda-forge
pcre2 10.40 hc3806b6_0 conda-forge
pexpect 4.8.0 pyh1a96a4e_2 conda-forge
pickleshare 0.7.5 py_1003 conda-forge
pillow 9.2.0 py310h023d228_4 conda-forge
pip 22.3.1 pyhd8ed1ab_0 conda-forge
pixman 0.40.0 h36c2ea0_0 conda-forge
pkginfo 1.9.2 pyhd8ed1ab_0 conda-forge
pkgutil-resolve-name 1.3.10 pyhd8ed1ab_0 conda-forge
platformdirs 2.6.0 pyhd8ed1ab_0 conda-forge
ply 3.11 py_1 conda-forge
poetry 1.3.1 py310hff52083_0 conda-forge
poetry-core 1.4.0 pyhd8ed1ab_0 conda-forge
poetry-plugin-export 1.2.0 pyhd8ed1ab_1 conda-forge
prometheus_client 0.15.0 pyhd8ed1ab_0 conda-forge
prompt-toolkit 3.0.36 pyha770c72_0 conda-forge
prompt_toolkit 3.0.36 hd8ed1ab_0 conda-forge
psutil 5.9.4 py310h5764c6d_0 conda-forge
pthread-stubs 0.4 h36c2ea0_1001 conda-forge
ptyprocess 0.7.0 pyhd3deb0d_0 conda-forge
pulseaudio 16.1 h126f2b6_0 conda-forge
pure_eval 0.2.2 pyhd8ed1ab_0 conda-forge
pycairo 1.23.0 py310hb8a676c_0 conda-forge
pycparser 2.21 pyhd8ed1ab_0 conda-forge
pydub 0.25.1 pyhd8ed1ab_0 conda-forge
pyglet 1.5.16 py310hff52083_1 conda-forge
pygments 2.13.0 pyhd8ed1ab_0 conda-forge
pylint 2.15.9 pyhd8ed1ab_0 conda-forge
pyopenssl 22.1.0 pyhd8ed1ab_0 conda-forge
pyqt 5.15.7 py310h29803b5_2 conda-forge
pyqt5-sip 12.11.0 py310hd8f1fbe_2 conda-forge
pyrr 0.10.3 py_0 conda-forge
pyrsistent 0.19.2 py310h5764c6d_0 conda-forge
pysocks 1.7.1 pyha2e5f31_6 conda-forge
python 3.10.8 h4a9ceb5_0_cpython conda-forge
python-dateutil 2.8.2 pyhd8ed1ab_0 conda-forge
python-fastjsonschema 2.16.2 pyhd8ed1ab_0 conda-forge
python-json-logger 2.0.1 pyh9f0ad1d_0 conda-forge
python_abi 3.10 3_cp310 conda-forge
pyyaml 6.0 py310h5764c6d_5 conda-forge
pyzmq 24.0.1 py310h330234f_1 conda-forge
qt-main 5.15.6 hf6cd601_5 conda-forge
qtconsole 5.4.0 pyhd8ed1ab_0 conda-forge
qtconsole-base 5.4.0 pyha770c72_0 conda-forge
qtpy 2.3.0 pyhd8ed1ab_0 conda-forge
rapidfuzz 2.13.6 py310heca2aa9_0 conda-forge
readline 8.1.2 h0f457ee_0 conda-forge
requests 2.28.1 pyhd8ed1ab_1 conda-forge
requests-toolbelt 0.10.1 pyhd8ed1ab_0 conda-forge
rich 12.6.0 pyhd8ed1ab_0 conda-forge
scipy 1.9.3 py310hdfbd76f_2 conda-forge
screeninfo 0.8.1 py310hff52083_1 conda-forge
secretstorage 3.3.3 py310hff52083_1 conda-forge
send2trash 1.8.0 pyhd8ed1ab_0 conda-forge
setuptools 65.6.3 pyhd8ed1ab_0 conda-forge
shellingham 1.5.0 pyhd8ed1ab_0 conda-forge
sip 6.7.5 py310hd8f1fbe_0 conda-forge
six 1.16.0 pyh6c4a22f_0 conda-forge
skia-pathops 0.7.4 py310hbf28c38_0 conda-forge
sniffio 1.3.0 pyhd8ed1ab_0 conda-forge
soupsieve 2.3.2.post1 pyhd8ed1ab_0 conda-forge
srt 3.5.2 py310hff52083_5 conda-forge
stack_data 0.6.2 pyhd8ed1ab_0 conda-forge
svgelements 1.9.0 pyhd8ed1ab_0 conda-forge
svt-av1 1.4.1 hcb278e6_0 conda-forge
terminado 0.17.1 pyh41d4057_0 conda-forge
tinycss2 1.2.1 pyhd8ed1ab_0 conda-forge
tk 8.6.12 h27826a3_0 conda-forge
toml 0.10.2 pyhd8ed1ab_0 conda-forge
tomli 2.0.1 pyhd8ed1ab_0 conda-forge
tomlkit 0.11.6 pyha770c72_0 conda-forge
tornado 6.2 py310h5764c6d_1 conda-forge
tqdm 4.64.1 pyhd8ed1ab_0 conda-forge
traitlets 5.8.0 pyhd8ed1ab_0 conda-forge
trove-classifiers 2022.12.1 pyhd8ed1ab_0 conda-forge
typing 3.10.0.0 pyhd8ed1ab_0 conda-forge
typing-extensions 4.4.0 hd8ed1ab_0 conda-forge
typing_extensions 4.4.0 pyha770c72_0 conda-forge
tzdata 2022g h191b570_0 conda-forge
urllib3 1.26.13 pyhd8ed1ab_0 conda-forge
virtualenv 20.17.1 py310hff52083_0 conda-forge
watchdog 2.2.0 py310hff52083_0 conda-forge
wcwidth 0.2.5 pyh9f0ad1d_2 conda-forge
webencodings 0.5.1 py_1 conda-forge
websocket-client 1.4.2 pyhd8ed1ab_0 conda-forge
wheel 0.38.4 pyhd8ed1ab_0 conda-forge
widgetsnbextension 4.0.4 pyhd8ed1ab_0 conda-forge
wrapt 1.14.1 py310h5764c6d_1 conda-forge
x264 1!164.3095 h166bdaf_2 conda-forge
x265 3.5 h924138e_3 conda-forge
xcb-util 0.4.0 h166bdaf_0 conda-forge
xcb-util-image 0.4.0 h166bdaf_0 conda-forge
xcb-util-keysyms 0.4.0 h166bdaf_0 conda-forge
xcb-util-renderutil 0.3.9 h166bdaf_0 conda-forge
xcb-util-wm 0.4.1 h166bdaf_0 conda-forge
xorg-fixesproto 5.0 h7f98852_1002 conda-forge
xorg-kbproto 1.0.7 h7f98852_1002 conda-forge
xorg-libice 1.0.10 h7f98852_0 conda-forge
xorg-libsm 1.2.3 hd9c2040_1000 conda-forge
xorg-libx11 1.7.2 h7f98852_0 conda-forge
xorg-libxau 1.0.9 h7f98852_0 conda-forge
xorg-libxdmcp 1.1.3 h7f98852_0 conda-forge
xorg-libxext 1.3.4 h7f98852_1 conda-forge
xorg-libxfixes 5.0.3 h7f98852_1004 conda-forge
xorg-libxrender 0.9.10 h7f98852_1003 conda-forge
xorg-renderproto 0.11.1 h7f98852_1002 conda-forge
xorg-xextproto 7.3.0 h7f98852_1002 conda-forge
xorg-xproto 7.0.31 h7f98852_1007 conda-forge
xz 5.2.6 h166bdaf_0 conda-forge
yaml 0.2.5 h7f98852_2 conda-forge
zeromq 4.3.4 h9c3ff4c_1 conda-forge
zipp 3.11.0 pyhd8ed1ab_0 conda-forge
zlib 1.2.13 h166bdaf_4 conda-forge
zstd 1.5.2 h6239696_4 conda-forge
Metadata
Metadata
Assignees
Type
Projects
Status
🆕 New