mirror of
https://github.com/3b1b/manim.git
synced 2025-07-30 21:44:19 +08:00
A few fixes to initial point_thickness implementation
This commit is contained in:
@ -1,9 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
GENERALLY_BUFFER_POINTS = True
|
|
||||||
|
|
||||||
PRODUCTION_QUALITY_DISPLAY_CONFIG = {
|
PRODUCTION_QUALITY_DISPLAY_CONFIG = {
|
||||||
"height" : 1440,
|
"height" : 1440,
|
||||||
"width" : 2560,
|
"width" : 2560,
|
||||||
@ -20,6 +17,8 @@ LOW_QUALITY_DISPLAY_CONFIG = {
|
|||||||
DEFAULT_POINT_DENSITY_2D = 25
|
DEFAULT_POINT_DENSITY_2D = 25
|
||||||
DEFAULT_POINT_DENSITY_1D = 200
|
DEFAULT_POINT_DENSITY_1D = 200
|
||||||
|
|
||||||
|
DEFAULT_POINT_THICKNESS = 4
|
||||||
|
|
||||||
#TODO, Make sure these are not needd
|
#TODO, Make sure these are not needd
|
||||||
DEFAULT_HEIGHT = PRODUCTION_QUALITY_DISPLAY_CONFIG["height"]
|
DEFAULT_HEIGHT = PRODUCTION_QUALITY_DISPLAY_CONFIG["height"]
|
||||||
DEFAULT_WIDTH = PRODUCTION_QUALITY_DISPLAY_CONFIG["width"]
|
DEFAULT_WIDTH = PRODUCTION_QUALITY_DISPLAY_CONFIG["width"]
|
||||||
|
14
displayer.py
14
displayer.py
@ -55,7 +55,7 @@ def paint_mobjects(mobjects, image_array = None):
|
|||||||
points[:,1] = -1*points[:,1]*height/space_height/2 + height/2
|
points[:,1] = -1*points[:,1]*height/space_height/2 + height/2
|
||||||
points, rgbs = add_thickness(
|
points, rgbs = add_thickness(
|
||||||
points.astype('int'), rgbs,
|
points.astype('int'), rgbs,
|
||||||
mobject.point_thickness,
|
mobject.point_thickness,
|
||||||
width, height
|
width, height
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -69,11 +69,14 @@ def paint_mobjects(mobjects, image_array = None):
|
|||||||
def add_thickness(pixel_indices, rgbs, thickness, width, height):
|
def add_thickness(pixel_indices, rgbs, thickness, width, height):
|
||||||
"""
|
"""
|
||||||
Imagine dragging each pixel around like a paintbrush in
|
Imagine dragging each pixel around like a paintbrush in
|
||||||
a square of pixels tickness x thickness big surrounding it
|
a plus-sign-shaped pixel arrangement surrounding it
|
||||||
"""
|
"""
|
||||||
|
thickness = adjusted_thickness(thickness, width, height)
|
||||||
original = np.array(pixel_indices)
|
original = np.array(pixel_indices)
|
||||||
original_rgbs = np.array(rgbs)
|
original_rgbs = np.array(rgbs)
|
||||||
for nudge in range(-thickness/2+1, thickness/2+1):
|
for nudge in range(-thickness/2+1, thickness/2+1):
|
||||||
|
if nudge == 0:
|
||||||
|
continue
|
||||||
for x, y in [[nudge, 0], [0, nudge]]:
|
for x, y in [[nudge, 0], [0, nudge]]:
|
||||||
pixel_indices = np.append(
|
pixel_indices = np.append(
|
||||||
pixel_indices,
|
pixel_indices,
|
||||||
@ -86,7 +89,12 @@ def add_thickness(pixel_indices, rgbs, thickness, width, height):
|
|||||||
(pixel_indices[:,1] >= 0) & \
|
(pixel_indices[:,1] >= 0) & \
|
||||||
(pixel_indices[:,1] < height)
|
(pixel_indices[:,1] < height)
|
||||||
return pixel_indices[admissibles], rgbs[admissibles]
|
return pixel_indices[admissibles], rgbs[admissibles]
|
||||||
|
|
||||||
|
def adjusted_thickness(thickness, width, height):
|
||||||
|
big_width = PRODUCTION_QUALITY_DISPLAY_CONFIG["width"]
|
||||||
|
big_height = PRODUCTION_QUALITY_DISPLAY_CONFIG["height"]
|
||||||
|
factor = (big_width + big_height) / (width + height)
|
||||||
|
return 1 + (thickness-1)/factor
|
||||||
|
|
||||||
def place_on_screen(points, rgbs, space_width, space_height):
|
def place_on_screen(points, rgbs, space_width, space_height):
|
||||||
"""
|
"""
|
||||||
|
@ -21,7 +21,7 @@ class Mobject(object):
|
|||||||
#Number of numbers used to describe a point (3 for pos, 3 for normal vector)
|
#Number of numbers used to describe a point (3 for pos, 3 for normal vector)
|
||||||
DEFAULT_CONFIG = {
|
DEFAULT_CONFIG = {
|
||||||
"color" : "white",
|
"color" : "white",
|
||||||
"point_thickness" : 4,
|
"point_thickness" : DEFAULT_POINT_THICKNESS,
|
||||||
"name" : None,
|
"name" : None,
|
||||||
}
|
}
|
||||||
DIM = 3
|
DIM = 3
|
||||||
@ -369,7 +369,7 @@ class Mobject2D(Mobject):
|
|||||||
"density" : DEFAULT_POINT_DENSITY_2D,
|
"density" : DEFAULT_POINT_DENSITY_2D,
|
||||||
}
|
}
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
digest_config(self, Mobject1D, kwargs)
|
digest_config(self, Mobject2D, kwargs)
|
||||||
self.epsilon = 1.0 / self.density
|
self.epsilon = 1.0 / self.density
|
||||||
Mobject.__init__(self, **kwargs)
|
Mobject.__init__(self, **kwargs)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user