mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
Scaffolding for AmicableNumbers Scene
This commit is contained in:
parent
b2e1024e83
commit
95efe9fd6e
1 changed files with 82 additions and 0 deletions
82
active_projects/aliquot.py
Normal file
82
active_projects/aliquot.py
Normal file
|
@ -0,0 +1,82 @@
|
|||
from big_ol_pile_of_manim_imports import *
|
||||
|
||||
|
||||
def get_factors(n):
|
||||
return filter(
|
||||
lambda k: (n % k) == 0,
|
||||
range(1, n)
|
||||
)
|
||||
|
||||
|
||||
class AmicableNumbers(Scene):
|
||||
CONFIG = {
|
||||
"n1": 28,
|
||||
"n2": 284,
|
||||
# "colors": [
|
||||
# BLUE, RED, YELLOW, GREEN,
|
||||
# MAROON_B, PURPLE_E, TEAL,
|
||||
# LIGHT_GREY, PINK, GREY_BROWN,
|
||||
# ]
|
||||
"colors": [
|
||||
BLUE_C,
|
||||
BLUE_B,
|
||||
BLUE_D,
|
||||
GREY_BROWN,
|
||||
GREEN_C,
|
||||
GREEN_B,
|
||||
GREEN_D,
|
||||
GREY,
|
||||
]
|
||||
}
|
||||
|
||||
def construct(self):
|
||||
self.show_n1()
|
||||
self.show_n1_factors()
|
||||
self.show_n1_factor_sum()
|
||||
self.show_n2_factors()
|
||||
self.show_n2_factor_sum()
|
||||
|
||||
def show_n1(self):
|
||||
dots = VGroup(*[Dot() for x in range(self.n1)])
|
||||
dots.set_color(BLUE)
|
||||
dots.set_sheen(0.2, UL)
|
||||
dots.arrange(RIGHT, buff=SMALL_BUFF)
|
||||
dots.set_width(FRAME_WIDTH - 1)
|
||||
|
||||
rects = self.get_all_factor_rectangles(dots)
|
||||
rects.rotate(90 * DEGREES)
|
||||
rects.arrange(RIGHT, buff=MED_SMALL_BUFF, aligned_edge=DOWN)
|
||||
for rect in rects:
|
||||
rect.first_col.set_stroke(WHITE, 3)
|
||||
rects.set_height(FRAME_HEIGHT - 1)
|
||||
|
||||
self.add(rects)
|
||||
|
||||
def show_n1_factors(self):
|
||||
pass
|
||||
|
||||
def show_n1_factor_sum(self):
|
||||
pass
|
||||
|
||||
def show_n2_factors(self):
|
||||
pass
|
||||
|
||||
def show_n2_factor_sum(self):
|
||||
pass
|
||||
|
||||
#
|
||||
def show_factors(self, dot_group):
|
||||
pass
|
||||
|
||||
def get_all_factor_rectangles(self, dot_group):
|
||||
n = len(dot_group)
|
||||
factors = get_factors(n)
|
||||
colors = it.cycle(self.colors)
|
||||
result = VGroup()
|
||||
for k, color in zip(factors, colors):
|
||||
group = dot_group.copy()
|
||||
group.set_color(color)
|
||||
group.arrange_in_grid(n_rows=k, buff=SMALL_BUFF)
|
||||
group.first_col = group[::(n // k)]
|
||||
result.add(group)
|
||||
return result
|
Loading…
Add table
Reference in a new issue