mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
Slight change to colormap
This commit is contained in:
parent
bf73938fd1
commit
fb0de62ef4
3 changed files with 21 additions and 12 deletions
|
@ -11,6 +11,7 @@ import numpy as np
|
||||||
from manimlib.constants import *
|
from manimlib.constants import *
|
||||||
from manimlib.utils.color import color_gradient
|
from manimlib.utils.color import color_gradient
|
||||||
from manimlib.utils.color import interpolate_color
|
from manimlib.utils.color import interpolate_color
|
||||||
|
from manimlib.utils.color import get_colormap_list
|
||||||
from manimlib.utils.config_ops import digest_config
|
from manimlib.utils.config_ops import digest_config
|
||||||
from manimlib.utils.iterables import batch_by_property
|
from manimlib.utils.iterables import batch_by_property
|
||||||
from manimlib.utils.iterables import list_update
|
from manimlib.utils.iterables import list_update
|
||||||
|
@ -1275,12 +1276,17 @@ class Mobject(object):
|
||||||
Pass in a glsl expression in terms of x, y and z which returns
|
Pass in a glsl expression in terms of x, y and z which returns
|
||||||
a float.
|
a float.
|
||||||
"""
|
"""
|
||||||
|
# TODO, add a version of this which changes the point data instead
|
||||||
|
# of the shader code
|
||||||
for char in "xyz":
|
for char in "xyz":
|
||||||
glsl_snippet = glsl_snippet.replace(char, "point." + char)
|
glsl_snippet = glsl_snippet.replace(char, "point." + char)
|
||||||
|
rgb_list = get_colormap_list(colormap)
|
||||||
self.set_color_by_code(
|
self.set_color_by_code(
|
||||||
"color.rgb = float_to_color({}, {}, {}, {});".format(
|
"color.rgb = float_to_color({}, {}, {}, {});".format(
|
||||||
glsl_snippet, float(min_value), float(max_value),
|
glsl_snippet,
|
||||||
get_colormap_code(colormap)
|
float(min_value),
|
||||||
|
float(max_value),
|
||||||
|
get_colormap_code(rgb_list)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return self
|
return self
|
||||||
|
|
|
@ -3,7 +3,6 @@ import re
|
||||||
import moderngl
|
import moderngl
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import copy
|
import copy
|
||||||
from matplotlib.cm import get_cmap
|
|
||||||
|
|
||||||
from manimlib.utils.directories import get_shader_dir
|
from manimlib.utils.directories import get_shader_dir
|
||||||
from manimlib.utils.file_ops import find_file
|
from manimlib.utils.file_ops import find_file
|
||||||
|
@ -153,14 +152,9 @@ def get_shader_code_from_file(filename):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def get_colormap_code(colormap="viridis"):
|
def get_colormap_code(rgb_list):
|
||||||
rgbs = get_cmap(colormap).colors # Make more general?
|
|
||||||
sparse_rgbs = [
|
|
||||||
rgbs[int(n)]
|
|
||||||
for n in np.linspace(0, len(rgbs) - 1, 9)
|
|
||||||
]
|
|
||||||
data = ",".join(
|
data = ",".join(
|
||||||
"vec3({}, {}, {})".format(*color)
|
"vec3({}, {}, {})".format(*rgb)
|
||||||
for color in sparse_rgbs
|
for rgb in rgb_list
|
||||||
)
|
)
|
||||||
return f"vec3[9]({data})"
|
return f"vec3[{len(rgb_list)}]({data})"
|
||||||
|
|
|
@ -2,6 +2,7 @@ import random
|
||||||
|
|
||||||
from colour import Color
|
from colour import Color
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
from matplotlib.cm import get_cmap
|
||||||
|
|
||||||
from manimlib.constants import PALETTE
|
from manimlib.constants import PALETTE
|
||||||
from manimlib.constants import WHITE
|
from manimlib.constants import WHITE
|
||||||
|
@ -112,3 +113,11 @@ def get_shaded_rgb(rgb, point, unit_normal_vect, light_source):
|
||||||
result = rgb + factor
|
result = rgb + factor
|
||||||
clip_in_place(rgb + factor, 0, 1)
|
clip_in_place(rgb + factor, 0, 1)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def get_colormap_list(map_name="viridis", n_colors=9):
|
||||||
|
rgbs = get_cmap(map_name).colors # Make more general?
|
||||||
|
return [
|
||||||
|
rgbs[int(n)]
|
||||||
|
for n in np.linspace(0, len(rgbs) - 1, n_colors)
|
||||||
|
]
|
||||||
|
|
Loading…
Add table
Reference in a new issue