From 9e1216397ae0462dfb631f4233173851527e70c3 Mon Sep 17 00:00:00 2001 From: Ben Hambrecht Date: Tue, 3 Apr 2018 19:39:24 +0200 Subject: [PATCH] experimental changes to old Pascal's triangle code --- once_useful_constructs/combinatorics.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/once_useful_constructs/combinatorics.py b/once_useful_constructs/combinatorics.py index 42340dfd..b804ad6e 100644 --- a/once_useful_constructs/combinatorics.py +++ b/once_useful_constructs/combinatorics.py @@ -85,12 +85,18 @@ class CountingScene(Scene): self.number = num_mob return self -class PascalsTriangle(VMobject): +class CombinationTexMobject(TexMobject): + def __init(self,n,k,**kwargs): + TexMobject.__init__(str(choose(n,k)),**kwargs) + + +class GeneralizedPascalsTriangle(VMobject): CONFIG = { "nrows" : 7, "height" : FRAME_HEIGHT - 1, "width" : 1.5*FRAME_X_RADIUS, - "portion_to_fill" : 0.7 + "portion_to_fill" : 0.7, + "submob_class" : CombinationTexMobject, } def generate_points(self): self.cell_height = float(self.height) / self.nrows @@ -98,16 +104,16 @@ class PascalsTriangle(VMobject): self.bottom_left = (self.cell_width * self.nrows / 2.0)*LEFT + \ (self.cell_height * self.nrows / 2.0)*DOWN num_to_num_mob = {} - self.coords_to_mobs = {} + self.coords_to_mobs = {} self.coords = [ (n, k) for n in range(self.nrows) for k in range(n+1) ] for n, k in self.coords: - num = choose(n, k) + num = choose(n, k) center = self.coords_to_center(n, k) - num_mob = TexMobject(str(num)) + num_mob = self.submob_class(n,k) #TexMobject(str(num)) scale_factor = min( 1, self.portion_to_fill * self.cell_height / num_mob.get_height(), @@ -167,7 +173,10 @@ class PascalsTriangle(VMobject): self.add(mob) return self - +class PascalsTriangle(GeneralizedPascalsTriangle): + CONFIG = { + "submob_class" : CombinationTexMobject, + }