extracted dice table

This commit is contained in:
Ben Hambrecht
2018-05-08 00:07:22 +02:00
parent 4e1e1e069f
commit de72ccb651
2 changed files with 53 additions and 22 deletions

View File

@ -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()

View File

@ -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()