.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_blender.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_blender.py: Blender =========================== This example show how to create a blender with Box2D .. GENERATED FROM PYTHON SOURCE LINES 7-75 .. 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 Blender(TestbedBase): name = "blender" def __init__(self, settings=None): super(Blender, self).__init__(settings=settings) dimensions = [30, 30] # the outer box box_shape = b2d.ChainShape() box_shape.create_loop( [ (0, 0), (0, dimensions[1]), (dimensions[0], dimensions[1]), (dimensions[0], 0), ] ) box = self.world.create_static_body( position=(0, 0), fixtures=b2d.fixture_def(shape=box_shape, friction=0) ) for i in range(20): circle = self.world.create_dynamic_body( position=(dimensions[0] / 2 + random.random(), 1 + random.random()), fixtures=b2d.fixture_def( density=1.0, shape=b2d.circle_shape(radius=1.0), restitution=1 ), angular_damping=0, linear_damping=0, ) body_a = self.world.create_static_body( position=(dimensions[0] / 2, dimensions[1] / 2) ) l = 7.2 body_b = self.world.create_dynamic_body( position=(dimensions[0] / 2, dimensions[1] / 2), shape=b2d.polygon_shape(box=[0.4, l]), density=1, angular_damping=0, linear_damping=0, ) joint = self.world.create_revolute_joint( body_a=body_a, body_b=body_b, local_anchor_a=(0, 0), local_anchor_b=(0, l), collide_connected=False, enable_motor=True, max_motor_torque=100000, motor_speed=3, ) if __name__ == "__main__": ani = b2d.testbed.run(Blender) ani .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 38.128 seconds) .. _sphx_glr_download_auto_examples_plot_blender.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_blender.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_blender.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_