SHARE
TWEET

Untitled

a guest Feb 14th, 2020 112 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class SelectionScene(Scene):
  2.     def construct(self):
  3.         text = VGroup(
  4.             TextMobject("Lorem ipsum dolor sit amet,"),
  5.             TextMobject("consectetur adipiscing elit,"),
  6.             TextMobject("sed do eiusmod tempor incididunt"),
  7.             TextMobject("ut labore et dolore magna aliqua.")
  8.         )
  9.         text.arrange(DOWN,aligned_edge=LEFT)
  10.         text_it = iter([*text])
  11.         rect = self.selection_rectangle(next(text_it))
  12.  
  13.         self.play(FadeIn(text))
  14.         self.play(GrowFromEdge(rect,LEFT))
  15.         for _ in range(len(text)-1):
  16.             self.play(ApplyFunction(
  17.                     lambda mob: mob.set_y(next(text_it).get_y()),
  18.                     rect
  19.                 )
  20.             )
  21.         self.wait()
  22.  
  23.     def selection_rectangle(self,text,buff=1,**kwargs):
  24.         Rectangle.CONFIG["color"] = YELLOW
  25.         Rectangle.CONFIG["stroke_opacity"] = 0
  26.         Rectangle.CONFIG["fill_opacity"] = 0.4
  27.         rect = Rectangle(
  28.             width=FRAME_WIDTH-2*buff,
  29.             height=text.get_height(),
  30.             **kwargs
  31.         )
  32.         rect.move_to(ORIGIN)
  33.         rect.set_y(text.get_y())
  34.         return rect
  35.  
  36. class Patronhexagon(Scene):
  37.     CONFIG={
  38.         "color_hexagon":BLUE_C,
  39.     }
  40.     def construct(self):
  41.         hexagon1 = self.get_hexagons()
  42.         hexagon2 = self.get_hexagons()
  43.         hexagon3 = self.get_hexagons()
  44.         hexagon4 = self.get_hexagons()
  45.         VGroup(hexagon1,hexagon2).arrange(RIGHT).move_to(ORIGIN)
  46.         VGroup(hexagon3,hexagon4).arrange(DOWN).move_to(ORIGIN)
  47.         hexagon3.shift(UP)
  48.         hexagon4.shift(DOWN)
  49.         h1 = VGroup(hexagon1,hexagon2,hexagon3,hexagon4).set_stroke(opacity=0.5)
  50.         h2 = h1.copy().set_stroke(opacity=0.5)
  51.         VGroup(h1,h2).arrange(RIGHT)
  52.         titulo=TextMobject("LaggedStart animation",color=WHITE,background_stroke_width=2).scale(2.5)
  53.  
  54.         self.play(
  55.         *[LaggedStartMap(ShowCreationThenDestruction,
  56.             h,
  57.             run_time=4.5,
  58.             lag_ratio=0.1,
  59.             rate_func=lambda t:smooth(t*1.3,inflection=11))for h in h1],
  60.         *[LaggedStartMap(ShowCreationThenDestruction,
  61.             h,
  62.             run_time=4.5,
  63.             lag_ratio=0.1,
  64.             rate_func=lambda t:smooth(t*1.3,inflection=11))for h in h2],
  65.         Write(titulo,run_time=7,rate_func=lambda t:there_and_back(1.1*t))
  66.         )
  67.  
  68.     def get_hexagons(self,partitions=6,rot=PI/2,stroke_init=1,stroke_end=25):
  69.         hexagon = VGroup()
  70.         for part in range(1,partitions+1):
  71.             hexag = RegularPolygon(n=6,color=self.color_hexagon)\
  72.                 .scale(part/partitions).rotate(rot)
  73.             stroke_gradient = (stroke_init - stroke_end) / part
  74.             hexag.set_stroke(None,stroke_init-stroke_gradient)
  75.             hexag.move_to(ORIGIN)
  76.             hexagon.add(hexag)
  77.  
  78.         hexagon.scale(2)
  79.         return hexagon
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top