ManimCommunity / ManimCommunity/manim

Unable to pass list of stroke_color for opengl

Open
#2,897 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

issue:bug opengl
Dominant language
Python
Stars
40.9k
Forks
3.1k
Avg merge
3d 12h
Merged PRs (30d)
25

Description

## Description of bug / unexpected behavior

It used to be the case you could pass a list of colors to create a stroke gradient, but from what I can tell it was broken from #2332 as I get the error `AttributeError: 'list' object has no attribute 'startswith'`

## Expected behavior

Passing a list of `stroke_color` creates a gradient

## How to reproduce the issue

Run the below scene with the opengl renderer

Code for reproducing the problem

```py
class Sample(Scene):

def construct(self):
self.add(Rectangle(stroke_color=[BLUE, GREEN]))
```

## Additional media files

Images/GIFs

## Logs
Terminal output

```
/home/k4pran/.cache/pypoetry/virtualenvs/manim-HpVtdmRp-py3.10/bin/python -m manim /home/k4pran/PycharmProjects/manim/sample.py --renderer opengl -pql
Manim Community v0.16.0.post0

╭───────────────────── Traceback (most recent call last) ──────────────────────╮
│ /home/k4pran/PycharmProjects/manim/manim/cli/render/commands.py:110 in │
│ render │
│ │
│ 107 │ │ │ while keep_running: │
│ 108 │ │ │ │ for SceneClass in scene_classes_from_file(file): │
│ 109 │ │ │ │ │ scene = SceneClass(renderer) │
│ ❱ 110 │ │ │ │ │ rerun = scene.render() │
│ 111 │ │ │ │ │ if rerun or config["write_all"]: │
│ 112 │ │ │ │ │ │ renderer.num_plays = 0 │
│ 113 │ │ │ │ │ │ continue │
│ │
│ /home/k4pran/PycharmProjects/manim/manim/scene/scene.py:221 in render │
│ │
│ 218 │ │ """ │
│ 219 │ │ self.setup() │
│ 220 │ │ try: │
│ ❱ 221 │ │ │ self.construct() │
│ 222 │ │ except EndSceneEarlyException: │
│ 223 │ │ │ pass │
│ 224 │ │ except RerunSceneException as e: │
│ │
│ /home/k4pran/PycharmProjects/manim/sample.py:9 in construct │
│ │
│ 6 │ def construct(self): │
│ 7 │ │ # self.add(Arc(angle=TAU, stroke_color=[PURE_BLUE, PURE_RED])) │
│ 8 │ │ # self.wait(duration=10) │
│ ❱ 9 │ │ self.add(Rectangle(stroke_color=[BLUE, GREEN])) │
│ │
│ /home/k4pran/PycharmProjects/manim/manim/mobject/geometry.py:2472 in │
│ __init__ │
│ │
│ 2469 │ │ close_new_points=True, │
│ 2470 │ │ **kwargs, │
│ 2471 │ ): │
│ ❱ 2472 │ │ super().__init__(UR, UL, DL, DR, color=color, **kwargs) │
│ 2473 │ │ self.stretch_to_fit_width(width) │
│ 2474 │ │ self.stretch_to_fit_height(height) │
│ 2475 │ │ v = self.get_vertices() │
│ │
│ /home/k4pran/PycharmProjects/manim/manim/mobject/geometry.py:1930 in │
│ __init__ │
│ │
│ 1927 │ """ │
│ 1928 │ │
│ 1929 │ def __init__(self, *vertices: Sequence[float], **kwargs): │
│ ❱ 1930 │ │ super().__init__(vertices, **kwargs) │
│ 1931 │
│ 1932 │
│ 1933 class RegularPolygram(Polygram): │
│ │
│ /home/k4pran/PycharmProjects/manim/manim/mobject/geometry.py:1751 in │
│ __init__ │
│ │
│ 1748 │ """ │
│ 1749 │ │
│ 1750 │ def __init__(self, *vertex_groups: Iterable[Sequence[float]], col │
│ ❱ 1751 │ │ super().__init__(color=color, **kwargs) │
│ 1752 │ │ │
│ 1753 │ │ for vertices in vertex_groups: │
│ 1754 │ │ │ first_vertex, *vertices = vertices │
│ │
│ /home/k4pran/PycharmProjects/manim/manim/mobject/types/opengl_vectorized_mob │
│ ject.py:133 in __init__ │
│ │
│ 130 │ │ if fill_color: │
│ 131 │ │ │ self.fill_color = Color(fill_color) │
│ 132 │ │ if stroke_color: │
│ ❱ 133 │ │ │ self.stroke_color = Color(stroke_color) │
│ 134 │ │
│ 135 │ def get_group_class(self): │
│ 136 │ │ return OpenGLVGroup │
│ │
│ /home/k4pran/.cache/pypoetry/virtualenvs/manim-HpVtdmRp-py3.10/lib/python3.1 │
│ 0/site-packages/colour.py:988 in __init__ │
│ │
│ 985 │ │ if isinstance(color, Color): │
│ 986 │ │ │ self.web = color.web │
│ 987 │ │ else: │
│ ❱ 988 │ │ │ self.web = color if color else 'black' │
│ 989 │ │ │
│ 990 │ │ self.equality = RGB_equivalence │
│ 991 │
│ │
│ /home/k4pran/.cache/pypoetry/virtualenvs/manim-HpVtdmRp-py3.10/lib/python3.1 │
│ 0/site-packages/colour.py:1006 in __setattr__ │
│ │
│ 1003 │ def __setattr__(self, label, value): │
│ 1004 │ │ if label not in ["_hsl", "equality"]: │
│ 1005 │ │ │ fc = getattr(self, 'set_' + label) │
│ ❱ 1006 │ │ │ fc(value) │
│ 1007 │ │ else: │
│ 1008 │ │ │ self.__dict__[label] = value │
│ 1009 │
│ │
│ /home/k4pran/.cache/pypoetry/virtualenvs/manim-HpVtdmRp-py3.10/lib/python3.1 │
│ 0/site-packages/colour.py:1084 in set_web │
│ │
│ 1081 │ set_hex_l = set_hex │
│ 1082 │ │
│ 1083 │ def set_web(self, value): │
│ ❱ 1084 │ │ self.hex = web2hex(value) │
│ 1085 │ │
│ 1086 │ ## range of color generation │
│ 1087 │
│ │
│ /home/k4pran/.cache/pypoetry/virtualenvs/manim-HpVtdmRp-py3.10/lib/python3.1 │
│ 0/site-packages/colour.py:664 in web2hex │
│ │
│ 661 │ │
│ 662 │ │
│ 663 │ """ │
│ ❱ 664 │ if web.startswith('#'): │
│ 665 │ │ if (LONG_HEX_COLOR.match(web) or │
│ 666 │ │ │ (not force_long and SHORT_HEX_COLOR.match(web))): │
│ 667 │ │ │ return web.lower() │
╰──────────────────────────────────────────────────────────────────────────────╯
AttributeError: 'list' object has no attribute 'startswith'

Process finished with exit code 1

```

## System specifications

System Details

- OS (with version, e.g., Windows 10 v2004 or macOS 10.15 (Catalina)):
- RAM:
- Python version (`python/py/python3 --version`):
- Installed modules (provide output from `pip list`):
```
PASTE HERE
```

LaTeX details

+ LaTeX distribution (e.g. TeX Live 2020):
+ Installed LaTeX packages:

FFMPEG

Output of `ffmpeg -version`:

```
PASTE HERE
```

## Additional comments

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with manim/mobject/types/opengl_vectorized_mobject.py at the OpenGL mobject initialization shown in the traceback, then reproduce the issue with Rectangle(stroke_color=[BLUE, GREEN]) using the OpenGL renderer. Done means the scene renders successfully and a list of stroke colors produces the expected gradient without the AttributeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.