Manim Vector Field
The vector field
VMobject object in Manim is defined in vector_field.py.
Codes in Vector_field.py
Available codes defined in manimlib.mobject.vector_field.py
Four classes,
VectorField(VGroup),
StreamLines(VGroup),
ShowPassingFlashWithThinningStrokeWidth(AnimationGroup) and
AnimatedStreamLines(VGroup) are defined.
Import
import numpy as np
import os
import itertools as it
from PIL import Image
import random
from manimlib.constants import *
from manimlib.animation.composition import AnimationGroup
from manimlib.animation.indication import ShowPassingFlash
from manimlib.mobject.geometry import Vector
from manimlib.mobject.types.vectorized_mobject import VGroup
from manimlib.mobject.types.vectorized_mobject import VMobject
from manimlib.utils.bezier import inverse_interpolate
from manimlib.utils.bezier import interpolate
from manimlib.utils.color import color_to_rgb
from manimlib.utils.color import rgb_to_color
from manimlib.utils.config_ops import digest_config
from manimlib.utils.rate_functions import linear
from manimlib.utils.simple_functions import sigmoid
from manimlib.utils.space_ops import get_norm
# from manimlib.utils.space_ops import normalize
Constant
DEFAULT_SCALAR_FIELD_COLORS = [BLUE_E, GREEN, YELLOW, RED]
Function Front
- def get_colored_background_image(scalar_field_func,
number_to_rgb_func,
pixel_height=DEFAULT_PIXEL_HEIGHT,
pixel_width=DEFAULT_PIXEL_WIDTH)
- def get_rgb_gradient_function(min_value=0, max_value=1,
colors=[BLUE, RED],
flip_alphas=True, # Why?
)
- def get_color_field_image_file(scalar_func,
min_value=0, max_value=2,
colors=DEFAULT_SCALAR_FIELD_COLORS
)
- def move_along_vector_field(mobject, func)
- def move_submobjects_along_vector_field(mobject, func)
- def move_points_along_vector_field(mobject, func)
- def apply_nudge(self, dt)
Class VectorField(VGroup)
class manimlib.mobject.vector_field.VectorField(VGroup)version 19Dec2019
Configuration
CONFIG = {
"delta_x": 0.5,
"delta_y": 0.5,
"x_min": int(np.floor(-FRAME_WIDTH / 2)),
"x_max": int(np.ceil(FRAME_WIDTH / 2)),
"y_min": int(np.floor(-FRAME_HEIGHT / 2)),
"y_max": int(np.ceil(FRAME_HEIGHT / 2)),
"min_magnitude": 0,
"max_magnitude": 2,
"colors": DEFAULT_SCALAR_FIELD_COLORS,
# Takes in actual norm, spits out displayed norm
"length_func": lambda norm: 0.45 * sigmoid(norm),
"opacity": 1.0,
"vector_config": {},
}
Functions
- def __init__(self, func, **kwargs)
- def get_vector(self, point, **kwargs)
Class StreamLines(VGroup)
class manimlib.mobject.vector_field.StreamLines(VGroup)version 19Dec2019
Configuration
CONFIG = {
# TODO, this is an awkward way to inherit
# defaults to a method.
"start_points_generator_config": {},
# Config for choosing start points
"x_min": -8,
"x_max": 8,
"y_min": -5,
"y_max": 5,
"delta_x": 0.5,
"delta_y": 0.5,
"n_repeats": 1,
"noise_factor": None,
# Config for drawing lines
"dt": 0.05,
"virtual_time": 3,
"n_anchors_per_line": 100,
"stroke_width": 1,
"stroke_color": WHITE,
"color_by_arc_length": True,
# Min and max arc lengths meant to define
# the color range, should color_by_arc_length be True
"min_arc_length": 0,
"max_arc_length": 12,
"color_by_magnitude": False,
# Min and max magnitudes meant to define
# the color range, should color_by_magnitude be True
"min_magnitude": 0.5,
"max_magnitude": 1.5,
"colors": DEFAULT_SCALAR_FIELD_COLORS,
"cutoff_norm": 15,
}
Functions
- def __init__(self, func, **kwargs)
- def get_start_points(self)
Class ShowPassingFlashWithThinningStrokeWidth(AnimationGroup)
class manimlib.mobject.vector_field.ShowPassingFlashWithThinningStrokeWidth(AnimationGroup)version 19Dec2019
Configuration
CONFIG = {
"n_segments": 10,
"time_width": 0.1,
"remover": True
}
Functions
- def __init__(self, vmobject, **kwargs)
Class AnimatedStreamLines(VGroup)
class manimlib.mobject.vector_field.AnimatedStreamLines(VGroup)version 19Dec2019
Configuration
CONFIG = {
"lag_range": 4,
"line_anim_class": ShowPassingFlash,
"line_anim_config": {
"run_time": 4,
"rate_func": linear,
"time_width": 0.3,
},
}
Functions
- def __init__(self, stream_lines, **kwargs)
- def update(self, dt)
Source and Reference
https://github.com/3b1b/manim
19Dec2019