def get_riemann_rectangles( self, graph, x_min = None, x_max = None, dx = 0.1, input_sample_type = "left", stroke_width = 1, start_color = BLUE, end_color = GREEN): x_min = x_min if x_min is not None else self.x_min x_max = x_max if x_max is not None else self.x_max rectangles = VGroup() for x in np.arange(x_min, x_max, dx): if input_sample_type == "left": sample_input = x elif input_sample_type == "right": sample_input = x+dx else: raise Exception("Invalid input sample type") graph_point = self.input_to_graph_point(sample_input, graph) points = VGroup(*map(VectorizedPoint, [ self.coords_to_point(x, 0), self.coords_to_point(x+dx, 0), graph_point ])) rect = Rectangle() rect.replace(points, stretch = True) rect.set_fill(opacity = 1) rectangles.add(rect) rectangles.gradient_highlight(start_color, end_color) rectangles.set_stroke(BLACK, width = stroke_width) return rectangles
def generate_points(self): body = Cube(side_length = 1) for dim, scale_factor in enumerate(self.body_dimensions): body.stretch(scale_factor, dim = dim) body.scale_to_fit_width(self.width) body.set_fill(self.shaded_body_color, opacity = 1) body.sort_submobjects(lambda p : p[2]) body[-1].set_fill(self.body_color) keyboard = VGroup(*[ VGroup(*[ Square(**self.key_color_kwargs) for x in range(12-y%2) ]).arrange_submobjects(RIGHT, buff = SMALL_BUFF) for y in range(4) ]).arrange_submobjects(DOWN, buff = MED_SMALL_BUFF) keyboard.stretch_to_fit_width( self.keyboard_width_to_body_width*body.get_width(), ) keyboard.stretch_to_fit_height( self.keyboard_height_to_body_height*body.get_height(), ) keyboard.next_to(body, OUT, buff = 0.1*SMALL_BUFF) keyboard.shift(MED_SMALL_BUFF*UP) body.add(keyboard) screen_plate = body.copy() screen_plate.stretch(self.screen_thickness/self.body_dimensions[2], dim = 2) screen = Rectangle( stroke_width = 0, fill_color = BLACK, fill_opacity = 1, ) screen.replace(screen_plate, stretch = True) screen.scale_in_place(self.screen_width_to_screen_plate_width) screen.next_to(screen_plate, OUT, buff = 0.1*SMALL_BUFF) screen_plate.add(screen) screen_plate.next_to(body, UP, buff = 0) screen_plate.rotate( self.open_angle, RIGHT, about_point = screen_plate.get_bottom() ) self.screen_plate = screen_plate self.screen = screen axis = Line( body.get_corner(UP+LEFT+OUT), body.get_corner(UP+RIGHT+OUT), color = BLACK, stroke_width = 2 ) self.axis = axis self.add(body, screen_plate, axis) self.rotate(5*np.pi/12, LEFT) self.rotate(np.pi/6, DOWN)
def get_riemann_rectangles( self, graph, x_min = None, x_max = None, dx = 0.1, input_sample_type = "left", stroke_width = 1, stroke_color = BLACK, fill_opacity = 1, start_color = None, end_color = None, show_signed_area = True, width_scale_factor = 1.001 ): x_min = x_min if x_min is not None else self.x_min x_max = x_max if x_max is not None else self.x_max if start_color is None: start_color = self.default_riemann_start_color if end_color is None: end_color = self.default_riemann_end_color rectangles = VGroup() x_range = np.arange(x_min, x_max, dx) colors = color_gradient([start_color, end_color], len(x_range)) for x, color in zip(x_range, colors): if input_sample_type == "left": sample_input = x elif input_sample_type == "right": sample_input = x+dx else: raise Exception("Invalid input sample type") graph_point = self.input_to_graph_point(sample_input, graph) points = VGroup(*map(VectorizedPoint, [ self.coords_to_point(x, 0), self.coords_to_point(x+width_scale_factor*dx, 0), graph_point ])) rect = Rectangle() rect.replace(points, stretch = True) if graph_point[1] < self.graph_origin[1] and show_signed_area: fill_color = invert_color(color) else: fill_color = color rect.set_fill(fill_color, opacity = fill_opacity) rect.set_stroke(stroke_color, width = stroke_width) rectangles.add(rect) return rectangles
def get_riemann_rectangles(self, x_min=None, x_max=None, dx=0.1, stroke_width=1, start_color=BLUE, end_color=GREEN): assert (hasattr(self, "func")) x_min = x_min if x_min is not None else self.x_min x_max = x_max if x_max is not None else self.x_max rectangles = VGroup() for x in np.arange(x_min, x_max, dx): points = VGroup(*map(VectorizedPoint, [ self.coords_to_point(x, 0), self.coords_to_point(x + dx, self.func(x + dx)), ])) rect = Rectangle() rect.replace(points, stretch=True) rect.set_fill(opacity=1) rectangles.add(rect) rectangles.gradient_highlight(start_color, end_color) rectangles.set_stroke(BLACK, width=stroke_width) return rectangles
def get_riemann_rectangles(self, x_min = None, x_max = None, dx = 0.1, stroke_width = 1, start_color = BLUE, end_color = GREEN): assert(hasattr(self, "func")) x_min = x_min if x_min is not None else self.x_min x_max = x_max if x_max is not None else self.x_max rectangles = VGroup() for x in np.arange(x_min, x_max, dx): points = VGroup(*map(VectorizedPoint, [ self.coords_to_point(x, 0), self.coords_to_point(x+dx, self.func(x+dx)), ])) rect = Rectangle() rect.replace(points, stretch = True) rect.set_fill(opacity = 1) rectangles.add(rect) rectangles.gradient_highlight(start_color, end_color) rectangles.set_stroke(BLACK, width = stroke_width) return rectangles