3b1b-manim/topics/functions.py

50 lines
1.1 KiB
Python
Raw Normal View History

2016-01-04 10:15:39 -08:00
from scipy import integrate
2016-04-19 00:20:19 -07:00
from mobject.vectorized_mobject import VMobject
2016-01-04 10:15:39 -08:00
from helpers import *
2016-04-19 00:20:19 -07:00
class FunctionGraph(VMobject):
2016-02-27 16:32:53 -08:00
CONFIG = {
2016-04-19 00:20:19 -07:00
"color" : BLUE_D,
"x_min" : -SPACE_WIDTH,
"x_max" : SPACE_WIDTH,
"num_steps" : 20,
}
def __init__(self, function, **kwargs):
self.function = function
2016-04-19 00:20:19 -07:00
VMobject.__init__(self, **kwargs)
def generate_points(self):
2016-04-19 00:20:19 -07:00
self.set_anchor_points([
x*RIGHT + self.function(x)*UP
for x in np.linspace(self.x_min, self.x_max, self.num_steps)
2016-04-19 00:20:19 -07:00
], mode = "smooth")
2016-09-16 14:06:44 -07:00
def get_function(self):
return self.function
2016-04-19 00:20:19 -07:00
class ParametricFunction(VMobject):
2016-02-27 16:32:53 -08:00
CONFIG = {
2016-04-19 00:20:19 -07:00
"t_min" : 0,
"t_max" : 1,
"epsilon" : 0.1,
}
def __init__(self, function, **kwargs):
self.function = function
2016-04-19 00:20:19 -07:00
VMobject.__init__(self, **kwargs)
def generate_points(self):
2016-04-19 00:20:19 -07:00
self.set_anchor_points([
self.function(t)
for t in np.arange(
self.t_min,
self.t_max+self.epsilon,
self.epsilon
)
2016-04-19 00:20:19 -07:00
], mode = "smooth")