.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_gauss_machine.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_gauss_machine.py: Gauss Machine =========================== This example shows how to approximate a gaussian function in a fun way .. GENERATED FROM PYTHON SOURCE LINES 7-81 .. container:: sphx-glr-animation .. raw:: html
.. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/.local/lib/python3.10/site-packages/b2d/testbed/backend/matplotlib_gif_gui/matplotlib_gif_gui.py:52: UserWarning: You passed in an explicit save_count=240 which is being ignored in favor of frames=240. self.ani = animation.FuncAnimation( | .. code-block:: default from b2d.testbed import TestbedBase import random import numpy import b2d class GaussMachine(TestbedBase): name = "Gauss Machine" def __init__(self, settings=None): super(GaussMachine, self).__init__(settings=settings) self.box_shape = 30, 20 box_shape = self.box_shape # outer box verts = numpy.array( [(0, box_shape[1]), (0, 0), (box_shape[0], 0), (box_shape[0], box_shape[1])] ) shape = b2d.chain_shape(vertices=numpy.flip(verts, axis=0)) box = self.world.create_static_body(position=(0, 0), shape=shape) # "bins" bin_height = box_shape[1] / 3 bin_width = 1 for x in range(0, box_shape[0], bin_width): box = self.world.create_static_body( position=(0, 0), shape=b2d.two_sided_edge_shape((x, 0), (x, bin_height)) ) # reflectors ref_start_y = int(bin_height + box_shape[1] / 10.0) ref_stop_y = int(box_shape[1] * 0.9) for x in range(0, box_shape[0] + 1): for y in range(ref_start_y, ref_stop_y): s = [0.5, 0][y % 2 == 0] shape = b2d.circle_shape(radius=0.3) box = self.world.create_static_body(position=(x + s, y), shape=shape) # particle system pdef = b2d.particle_system_def( repulsive_strength=1.0, # viscous_strength=0.9, # spring_strength=0.0, # damping_strength=100.5, # pressure_strength=1.0, # color_mixing_strength=0.05, density=2, ) psystem = self.world.create_particle_system(pdef) psystem.radius = 0.1 psystem.damping = 0.5 # linear emitter emitter_pos = (self.box_shape[0] / 2, self.box_shape[1] + 10) emitter_def = b2d.RandomizedLinearEmitterDef() emitter_def.emite_rate = 400 emitter_def.lifetime = 25 emitter_def.size = (10, 1) emitter_def.transform = b2d.Transform(emitter_pos, b2d.Rot(0)) self.emitter = b2d.RandomizedLinearEmitter(psystem, emitter_def) def pre_step(self, dt): self.emitter.step(dt) if __name__ == "__main__": ani = b2d.testbed.run(GaussMachine) ani .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 46.497 seconds) .. _sphx_glr_download_auto_examples_plot_gauss_machine.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_gauss_machine.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_gauss_machine.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_