3b1b-manim/topics/functions.py

51 lines
1.3 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,
"space_unit_to_num" : 1,
"epsilon" : 0.5,
}
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 pre_x in np.arange(self.x_min, self.x_max, self.epsilon)
for x in [self.space_unit_to_num*pre_x]
], mode = "smooth")
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)
], mode = "smooth")
class Axes(VMobject):
def generate_points(self):
self.x_axis = NumberLine(**kwargs)
self.y_axis = NumberLine(**kwargs).rotate(np.pi/2)
self.add(self.x_axis, self.y_axis)