.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_function_shape.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_function_shape.py: Function Shape =========================== This example show how to create a shape from a mathematical function. In this example we use f(x) = sin(x) + log(x) + 5.5 .. GENERATED FROM PYTHON SOURCE LINES 8-43 .. 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 FunctionShape(TestbedBase): name = "Function Shape" def __init__(self, settings=None): super(FunctionShape, self).__init__(settings=settings) x = numpy.linspace(start=1, stop=30, num=100) y = numpy.sin(x) * numpy.log(x) + 5.5 verts = numpy.stack([x, y], -1) verts = numpy.require(verts, requirements=["C"]) shape = b2d.chain_shape(vertices=numpy.flip(verts, axis=0)) box = self.world.create_static_body(position=(0, 0), shape=shape) for i in range(30): box = self.world.create_dynamic_body( position=(10 + random.random() * 10, random.random() * 10 + 10), shape=b2d.circle_shape(pos=(0, 0), radius=0.7), density=1.0, ) if __name__ == "__main__": ani = b2d.testbed.run(FunctionShape) ani .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 35.368 seconds) .. _sphx_glr_download_auto_examples_plot_function_shape.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_function_shape.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_function_shape.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_