Skip to content

fix(vectorized_mobject,mobject): Removing explicit opacity attributes…#3862

Open
MrDiver wants to merge 9 commits into
ManimCommunity:mainfrom
MrDiver:replacing_opacity
Open

fix(vectorized_mobject,mobject): Removing explicit opacity attributes…#3862
MrDiver wants to merge 9 commits into
ManimCommunity:mainfrom
MrDiver:replacing_opacity

Conversation

@MrDiver

@MrDiver MrDiver commented Jul 15, 2024

Copy link
Copy Markdown
Member
  • Removing all references to fill_opacity and stroke_opacity and replacing them with properties
  • Should result in ManimColor holding the only reference to opacity for Mobjects

Comment thread manim/mobject/types/vectorized_mobject.py Fixed
Comment thread manim/mobject/types/vectorized_mobject.py Fixed

@JasonGrace2282 JasonGrace2282 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick stuff I noticed ;)

Comment thread manim/mobject/geometry/arc.py Outdated

from __future__ import annotations

from typing_extensions import deprecated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use manim.utils.deprecation.deprecated?

Comment thread manim/utils/color/core.py
The opacity of the ManimColor
"""

def opacity(self, opacity=None):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def opacity(self, opacity=None):
def opacity(self, opacity: float | None = None) -> ManimColor | float:

Comment on lines +166 to +167
# if fill_color is not None or stroke_color is not None:
# color = None

Check notice

Code scanning / CodeQL

Commented-out code

This comment appears to contain commented-out code.
Comment thread manim/utils/color/core.py
Comment on lines +524 to +555
@overload
def opacity(self, opacity: float) -> ManimColor:
"""Returns a new ManimColor with the same color and the given opacity

Parameters
----------
opacity : float
The opacity for the new ManimColor

Returns
-------
ManimColor
The new ManimColor object with changed opacity
"""

@overload
def opacity(self, opacity: None) -> float:
"""Returns the opacity of the current ManimColor in a range from zero to one

Returns
-------
float
The opacity of the ManimColor
"""

def opacity(self, opacity=None):
"""Returns a new ManimColor with the same color and a new opacity or changes the opacity"""
if opacity is None:
return self._internal_value[3]
tmp = self._internal_value.copy()
tmp[3] = opacity
return ManimColor.parse(tmp)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this overload. Could it be, instead, something like ManimColor.with_opacity(opacity) to return a new ManimColor with that different opacity, and ManimColor.get_opacity() or ManimColor.opacity as a property to get the current opacity?

Suggested change
@overload
def opacity(self, opacity: float) -> ManimColor:
"""Returns a new ManimColor with the same color and the given opacity
Parameters
----------
opacity : float
The opacity for the new ManimColor
Returns
-------
ManimColor
The new ManimColor object with changed opacity
"""
@overload
def opacity(self, opacity: None) -> float:
"""Returns the opacity of the current ManimColor in a range from zero to one
Returns
-------
float
The opacity of the ManimColor
"""
def opacity(self, opacity=None):
"""Returns a new ManimColor with the same color and a new opacity or changes the opacity"""
if opacity is None:
return self._internal_value[3]
tmp = self._internal_value.copy()
tmp[3] = opacity
return ManimColor.parse(tmp)
def with_opacity(self, opacity: float) -> ManimColor:
"""Returns a new ManimColor with the same color and the given opacity.
Parameters
----------
opacity
The opacity for the new ManimColor.
Returns
-------
ManimColor
The new ManimColor object with changed opacity.
"""
tmp = self._internal_value.copy()
tmp[3] = opacity
return ManimColor.parse(tmp)
@property
def opacity(self) -> float:
"""Returns the opacity of the current ManimColor, in a range from zero to one.
Returns
-------
float
The opacity of the ManimColor.
"""
return self._internal_value[3]

chopan050 and others added 3 commits June 11, 2026 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🆕 New

Development

Successfully merging this pull request may close these issues.

4 participants