| from manim import * | |
| class Atom(Dot): | |
| def __init__(self, pos=ORIGIN, color = RED, prob = 0.1): | |
| super().__init__(point=pos, radius=.07, stroke_width=0, fill_opacity=1, color=color) | |
| self.prob = prob | |
| self.add_updater(self.updater) | |
| def updater(self,mobj,dt): | |
| if (self.prob > 0) and (np.random.uniform(0,1) <= self.prob*dt): | |
| self.prob = 0 | |
| self.set_color(YELLOW) | |
| elif self.prob <= 0: | |
| self.prob -= dt | |
| if self.prob <= 0.5: | |
| self.set_color(GRAY) | |
| class becquerel(Scene): | |
| def construct(self): | |
| atoms = VGroup( | |
| Atom(pos=[np.random.uniform(-7,1),np.random.uniform(-3.5,3.5),0],prob=0.1) | |
| for _ in range(500) | |
| ) | |
| steps = 40 | |
| self.add(atoms) | |
| ax = Axes( | |
| x_range=[0,steps,10], | |
| y_range=[0,len(atoms),50], | |
| x_length=4.5, | |
| y_length=6, | |
| tips=False, | |
| ).add_coordinates().to_edge(RIGHT,buff=0) | |
| self.add(ax) | |
| lines = VGroup( | |
| Line(ax.c2p(0,len(atoms)),ax.c2p(0,len(atoms))) | |
| ) | |
| self.add(lines) | |
| self.wait(1) | |
| for t in range(1,steps): | |
| num = 0 | |
| for atom in atoms: | |
| if atom.prob > 0: | |
| num += 1 | |
| line = Line(lines[-1].get_end(),ax.c2p(t,num)) | |
| self.play(Create(line)) | |
| lines += line |