Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Added a clamp function

Sridhar Ramesh04c8477ea032
diff --git a/helpers.py b/helpers.py
index d500b7a96..87a04a463 100644
--- a/helpers.py
+++ b/helpers.py
@@ -304,6 +304,13 @@ def digest_locals(obj, keys = None):
def interpolate(start, end, alpha):
return (1-alpha)*start + alpha*end
+def clamp(lower, upper, val):
+ if val < lower:
+ return lower
+ elif val > upper:
+ return upper
+ return val
+
def center_of_mass(points):
points = [np.array(point).astype("float") for point in points]
return sum(points) / len(points)