Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions manim/camera/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@ def __init__(self, video_quality_config, background=None, **kwargs):
"frame_height",
"frame_width",
"frame_rate",
"background_color",
"background_opacity",
]:
setattr(self, attr, kwargs.get(attr, config[attr]))

for attr in ["background_color", "background_opacity"]:
setattr(self, f"_{attr}", kwargs.get(attr, config[attr]))

# This one is in the same boat as the above, but it doesn't have the
# same name as the corresponding key so it has to be handled on its own
self.max_allowable_norm = config["frame_width"]
Expand All @@ -117,6 +118,24 @@ def __deepcopy__(self, memo):
self.canvas = None
return copy.copy(self)

@property
def background_color(self):
return self._background_color

@background_color.setter
def background_color(self, color):
self._background_color = color
self.init_background()

@property
def background_opacity(self):
return self._background_opacity

@background_opacity.setter
def background_opacity(self, alpha):
self._background_opacity = alpha
self.init_background()

def type_or_raise(self, mobject):
"""Return the type of mobject, if it is a type that can be rendered.

Expand Down
4 changes: 4 additions & 0 deletions manim/scene/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def __init__(self, renderer=None, **kwargs):

self.setup()

@property
def camera(self):
return self.renderer.camera

def render(self):
"""
Render this Scene.
Expand Down
20 changes: 19 additions & 1 deletion tests/test_color.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
import pytest
from manim import Camera, tempconfig, config
import numpy as np

from manim import Camera, Scene, tempconfig, config


def test_import_color():
import manim.utils.color as C

C.WHITE


def test_background_color():
S = Scene()
S.camera.background_color = "#ff0000"
S.renderer.update_frame(S)
assert np.all(S.renderer.get_frame()[0, 0] == np.array([255, 0, 0, 255]))

S.camera.background_color = "#436f80"
S.renderer.update_frame(S)
assert np.all(S.renderer.get_frame()[0, 0] == np.array([67, 111, 128, 255]))

S.camera.background_color = "#bbffbb"
S.camera.background_opacity = 0.5
S.renderer.update_frame(S)
assert np.all(S.renderer.get_frame()[0, 0] == np.array([187, 255, 187, 127]))