from manim import * from manim_physics import * from manim.utils.color import random_color import random class NormalDistributionVisualisation(SpaceScene): def construct(self): # Create 40 small circles inside the cone btw = RIGHT/3 num_circles = 12 circles = VGroup() for i in range(num_circles): for j in range(20): # вертикальная составляющая количества выкидываемых шаров circle = Circle(radius=0.08).shift(4*UP + UP*j - num_circles/2*btw + i*btw) circle.set_fill(random_color(), 1) circles.add(circle) self.add(circles) # Create the cone width = 8 height = 3.8 otverstie = 0.31 wall1 = Line([-width, height, 0], [-otverstie, 0.65, 0]) wall2 = Line([width, height, 0], [otverstie, 0.65, 0]) walls = VGroup(wall1, wall2).shift(UP*2) self.add(walls) # Create the obstacles obstacles = VGroup()
btw_X = RIGHT*0.8 btw_Y = DOWN*0.8 H = 3 W = 14 for i in range(-H, H-2): for j in range(-W, W+1): r = Square().shift(btw_X * j, btw_Y * i).rotate(PI/4).scale(0.1) r.set_fill(GREY, 1) obstacles.add(r)
self.wait(30) """ from manim import * from manim_physics import * # use a SpaceScene to utilize all specific rigid-mechanics methods class TwoObjectsFalling(SpaceScene): def construct(self):
from manim import *
from manim_physics import *
from manim.utils.color import random_color
import random
class NormalDistributionVisualisation(SpaceScene):
def construct(self):
# Create 40 small circles inside the cone
btw = RIGHT/3
num_circles = 12
circles = VGroup()
for i in range(num_circles):
for j in range(20): # вертикальная составляющая количества выкидываемых шаров
circle = Circle(radius=0.08).shift(4*UP + UP*j - num_circles/2*btw + i*btw)
circle.set_fill(random_color(), 1)
circles.add(circle)
self.add(circles)
# Create the cone
width = 8
height = 3.8
otverstie = 0.31
wall1 = Line([-width, height, 0], [-otverstie, 0.65, 0])
wall2 = Line([width, height, 0], [otverstie, 0.65, 0])
walls = VGroup(wall1, wall2).shift(UP*2)
self.add(walls)
# Create the obstacles
obstacles = VGroup()
btw_X = RIGHT*0.8
btw_Y = DOWN*0.8
H = 3
W = 14
for i in range(-H, H-2):
for j in range(-W, W+1):
r = Square().shift(btw_X * j, btw_Y * i).rotate(PI/4).scale(0.1)
r.set_fill(GREY, 1)
obstacles.add(r)
obstacles.scale(0.7)
self.add(obstacles)
# Create the "Ш"-shaped container
container = VGroup()
container_width = 14
container_height = 4.4
container_left = Line([-container_width / 2, -container_height / 2, 0], [-container_width / 2, container_height / 2, 0])
container_right = Line([container_width / 2, -container_height / 2, 0], [container_width / 2, container_height / 2, 0])
container_bottom = Line([-container_width / 2, -container_height / 2, 0], [container_width / 2, -container_height / 2, 0])
n = 49 # количество отсеков
step = container_width/n
for i in range(0,n):
x_from = -container_width / 2 + step*i
y_from = -container_height / 2
x_to = -container_width / 2 + step*i
y_to = container_height / 2
middle_line = Line([x_from, y_from, 0], [x_to, y_to, 0])
container.add(middle_line)
container.add(container_left)
container.add(container_right)
container.add(container_bottom)
container.shift(DOWN*2)
self.add(container)
# Add physics simulation
self.make_rigid_body(*circles)
self.make_static_body(obstacles)
self.make_static_body(walls)
self.make_static_body(container)
self.wait(30)
"""
from manim import *
from manim_physics import *
# use a SpaceScene to utilize all specific rigid-mechanics methods
class TwoObjectsFalling(SpaceScene):
def construct(self):
circle = Circle().shift(UP).scale(0.1)
circle.set_fill(RED, 1)
circle.shift(DOWN + RIGHT)
wall1 = Line([-4, 3.5, 0], [0, 0, 0])
wall2 = Line([4, 3.5, 0], [0, 0, 0])
walls = VGroup(wall1, wall2)
self.add(walls)
self.play(
DrawBorderThenFill(circle),
)
self.make_rigid_body(circle) # Mobjects will move with gravity
self.make_static_body(walls) # Mobjects will stay in place
self.wait(5)
# during wait time, the circle and rect would move according to the simulate updater
"""
Помогите разобраться, почему падающие шарики не бьются о преграды на пути :((((