Fapensang

manim spinning shuriken wallpaper

Aug 15th, 2025
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.34 KB | None | 0 0
  1. import numpy as np
  2. from manim import *
  3.  
  4. class Shuriken3(Scene):
  5.     def construct(self):
  6.         # Base square
  7.         side_len = 1
  8.         opacity = 0
  9.         square = Square(side_length=side_len, color=WHITE, fill_opacity=0)
  10.  
  11.         # Half of the side length, for positioning
  12.         h = side_len / 2
  13.  
  14.         # Four triangles (one on each side)
  15.         triangles = []
  16.  
  17.         # Top triangle
  18.         tri_top = Polygon(
  19.             [ -h,  h, 0 ],   # left corner of top side
  20.             [  h,  h, 0 ],   # right corner of top side
  21.             [  0,  h + side_len, 0 ],  # tip above
  22.             color=WHITE, fill_opacity=opacity
  23.         )
  24.         triangles.append(tri_top)
  25.  
  26.         # Bottom triangle
  27.         tri_bottom = Polygon(
  28.             [ -h, -h, 0 ],
  29.             [  h, -h, 0 ],
  30.             [  0, -h - side_len, 0 ],
  31.             color=WHITE, fill_opacity=opacity
  32.         )
  33.         triangles.append(tri_bottom)
  34.  
  35.         # Left triangle
  36.         tri_left = Polygon(
  37.             [ -h,  h, 0 ],
  38.             [ -h, -h, 0 ],
  39.             [ -h - side_len, 0, 0 ],
  40.             color=WHITE, fill_opacity=opacity
  41.         )
  42.         triangles.append(tri_left)
  43.  
  44.         # Right triangle
  45.         tri_right = Polygon(
  46.             [  h,  h, 0 ],
  47.             [  h, -h, 0 ],
  48.             [  h + side_len, 0, 0 ],
  49.             color=WHITE, fill_opacity=opacity
  50.         )
  51.         triangles.append(tri_right)
  52.  
  53.         # Circle for end transition
  54.         end_circle = Circle(radius = 1.5,color=WHITE,fill_opacity=0)
  55.  
  56.         # Group square + triangle
  57.         #shuriken_shape = VGroup(square, *triangles)
  58.  
  59.         # Animate all with overlap (lag_ratio controls how much they overlap)
  60.         self.add(square)
  61.         #self.wait(1)
  62.         self.play(
  63.             AnimationGroup(
  64.                 Create(tri_right),
  65.                 Create(tri_top),
  66.                 Create(tri_left),
  67.                 Create(tri_bottom),
  68.                 lag_ratio = 0.2
  69.             ),
  70.             run_time = 1
  71.         )
  72.         # Save states of triangles so they can continuously be restored during animation
  73.         tri_right.save_state()
  74.         #tri_left.save_state()
  75.         #tri_top.save_state()
  76.         #tri_bottom.save_state()
  77.  
  78.         def update_triangle(mob, start_pos, end_pos, rotation_angle, alpha):
  79.             mob.restore()
  80.             mob.shift(interpolate(start_pos, end_pos, alpha))
  81.             mob.rotate(interpolate(0, rotation_angle, alpha), about_point=mob.get_center())
  82.  
  83.         # Save states so mob.restore() has a baseline
  84.         for t in triangles:
  85.             t.save_state()
  86.  
  87.         self.play(
  88.             AnimationGroup(
  89.                 UpdateFromAlphaFunc(tri_top, lambda m, a: update_triangle(m, UP*0, UP*1, PI, a)),
  90.                 UpdateFromAlphaFunc(tri_bottom, lambda m, a: update_triangle(m, DOWN*0, DOWN*1, PI, a)),
  91.                 UpdateFromAlphaFunc(tri_left, lambda m, a: update_triangle(m, LEFT*0, LEFT*1, PI, a)),
  92.                 UpdateFromAlphaFunc(tri_right, lambda m, a: update_triangle(m, RIGHT*0, RIGHT*1, PI, a)),
  93.                 lag_ratio=0.1
  94.             ),
  95.             run_time=1
  96.         )
  97.         self.play(
  98.             AnimationGroup(
  99.                 Rotate(square,-45*DEGREES,about_point=ORIGIN),
  100.                 Rotate(tri_right,45*DEGREES,about_point=ORIGIN),
  101.                 Rotate(tri_top,45*DEGREES,about_point=ORIGIN),
  102.                 Rotate(tri_left,45*DEGREES,about_point=ORIGIN),
  103.                 Rotate(tri_bottom,45*DEGREES,about_point=ORIGIN),
  104.                 lag_ratio=0.07,
  105.                 run_time=0.7
  106.             )
  107.         )
  108.         self.play(
  109.             AnimationGroup(
  110.                 tri_right.animate.shift(DOWN*np.sqrt(4.5)+LEFT*np.sqrt(4.5)),
  111.                 tri_left.animate.shift(UP*np.sqrt(4.5)+RIGHT*np.sqrt(4.5)),
  112.                 tri_top.animate.shift(DOWN*np.sqrt(4.5)+RIGHT*np.sqrt(4.5)),
  113.                 tri_bottom.animate.shift(UP*np.sqrt(4.5)+LEFT*np.sqrt(4.5)),
  114.                 Create(end_circle)),
  115.                 run_time=0.4
  116.             )
  117.        
  118.         # Last rotation to return to default state
  119.         angle = 405 + 15 #little overshoot
  120.         self.play(
  121.             AnimationGroup(
  122.                 Rotate(square,-angle*DEGREES,about_point=ORIGIN),
  123.                 Rotate(tri_right,-angle*DEGREES,about_point=ORIGIN),
  124.                 Rotate(tri_left,-angle*DEGREES,about_point=ORIGIN),
  125.                 Rotate(tri_bottom,-angle*DEGREES,about_point=ORIGIN),
  126.                 Rotate(tri_top,-angle*DEGREES,about_point=ORIGIN),
  127.                 run_time=1.5
  128.             )
  129.         )
  130.         # Make circle fade away again
  131.         angle = -15
  132.         self.play(
  133.             FadeOut(end_circle,runtime=0.5),
  134.             AnimationGroup(
  135.                 Rotate(square,-angle*DEGREES,about_point=ORIGIN),
  136.                 Rotate(tri_right,-angle*DEGREES,about_point=ORIGIN),
  137.                 Rotate(tri_left,-angle*DEGREES,about_point=ORIGIN),
  138.                 Rotate(tri_bottom,-angle*DEGREES,about_point=ORIGIN),
  139.                 Rotate(tri_top,-angle*DEGREES,about_point=ORIGIN),
  140.                 run_time=0.5
  141.             )
  142.         )
  143.         self.play(
  144.             AnimationGroup(
  145.                 Uncreate(tri_right),
  146.                 Uncreate(tri_top),
  147.                 Uncreate(tri_left),
  148.                 Uncreate(tri_bottom),
  149.                 #Uncreate(end_circle),
  150.                 #Rotate(square,angle=PI/2,rate_func=rate_functions.ease_in_out_back),
  151.                 #square.scale(0.7),
  152.                 #square.scale(1/0.7),
  153.                 #Uncreate(square,reverse_rate_function=rate_functions.exponential_decay),
  154.                 #Create(square),
  155.                 square.animate.rotate(angle=180*DEGREES,about_point=ORIGIN),
  156.                 run_time = 1.5,
  157.                 lag_ratio = 0.3
  158.             )
  159.         )
  160.         #self.play(
  161.         #    Rotate(square,angle=PI/2,run_time=0.3,rate_func=rate_functions.ease_in_out_back)
  162.         #)
  163.         # Maybe reactive this last part again but it looks more snappy if the triangles start flying faster
  164.         '''
  165.        self.play(
  166.            AnimationGroup(
  167.                FadeOut(tri_right),
  168.                FadeOut(tri_top),
  169.                FadeOut(tri_left),
  170.                FadeOut(tri_bottom),
  171.                #FadeOut(end_circle),
  172.                run_time = 1,
  173.                lag_ratio = 0.2
  174.            )
  175.        )
  176.        '''
Advertisement
Add Comment
Please, Sign In to add comment