A community-maintained Python framework for creating mathematical animations.
extracted dice table
Ben Hambrechtde72ccb651d1
diff --git a/active_projects/eop/chapter1/various_intro_visuals.py b/active_projects/eop/chapter1/various_intro_visuals.pyindex 6e7151f23..aba40fe6a 100644--- a/active_projects/eop/chapter1/various_intro_visuals.py+++ b/active_projects/eop/chapter1/various_intro_visuals.py@@ -45,35 +45,16 @@ class RandyFlipsAndStacks(Scene):-class TwoDiceTable(Scene):+class TwoDiceTableScene(Scene):def construct(self):- table = VGroup()- cell_size = 1- colors = color_gradient([RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE], 13)-- for i in range(1,7):- for j in range(1,7):- cell = Square(side_length = cell_size)- cell.set_fill(color = colors[i+j], opacity = 0.8)- label = Integer(i+j)- label.move_to(cell)- cell.add(label)- cell.move_to(i*cell_size*RIGHT + j*cell_size*DOWN)- table.add(cell)+ table = TwoDiceTable(cell_size = 1)table.center()self.add(table)- row1 = RowOfDice().match_width(table)- print row1.is_subpath- row2 = row1.copy().rotate(-TAU/4)- print row2.is_subpath- row1.next_to(table, UP)- row2.next_to(table, LEFT)- table.add(row1, row2)- table.center()+diff --git a/active_projects/eop/reusables/dice.py b/active_projects/eop/reusables/dice.pyindex 777fdfedc..7596e8259 100644--- a/active_projects/eop/reusables/dice.py+++ b/active_projects/eop/reusables/dice.py@@ -1,4 +1,6 @@from mobject.svg.svg_mobject import *+from mobject.geometry import *+from mobject.numbers import *class DieFace(SVGMobject):@@ -24,3 +26,51 @@ class RowOfDice(VGroup):self.add(new_die)self.move_to(ORIGIN)++class TwoDiceTable(VMobject):+ CONFIG = {+ "cell_size" : 1,+ "label_scale": 0.7+ }++ def __init__(self, **kwargs):++ VMobject.__init__(self, **kwargs)+ colors = color_gradient([RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE], 13)++ self.cells = VGroup()+ self.labels = VGroup()+ for i in range(1,7):+ for j in range(1,7):+ cell = Square(side_length = self.cell_size)+ cell.set_fill(color = colors[i+j], opacity = 0.8)+ cell.move_to(i*self.cell_size*DOWN + j*self.cell_size*RIGHT)+ self.cells.add(cell)+ label = Integer(i+j).scale(self.label_scale)+ label.move_to(cell)+ self.labels.add(label)+++ self.add(self.cells, self.labels)+ row1 = RowOfDice().match_width(self)+ row2 = row1.copy().rotate(-TAU/4)+ row1.next_to(self, UP)+ row2.next_to(self, LEFT)+ self.rows = VGroup(row1, row2)+ self.add(self.rows)+ self.center()+++++++++++++++