.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/feature_demo/spheres.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__gallery_feature_demo_spheres.py: Sphere Geometry =============== Example showing different types of geometric spheres. .. GENERATED FROM PYTHON SOURCE LINES 7-70 .. image-sg:: /_gallery/feature_demo/images/sphx_glr_spheres_001.webp :alt: spheres :srcset: /_gallery/feature_demo/images/sphx_glr_spheres_001.webp :class: sphx-glr-single-img .. code-block:: Python import numpy as np from rendercanvas.auto import RenderCanvas, loop import pygfx as gfx canvas = RenderCanvas() renderer = gfx.renderers.WgpuRenderer(canvas) scene = gfx.Scene() grid = gfx.Grid( None, gfx.GridMaterial( major_step=5, thickness_space="world", major_thickness=0.1, infinite=True, ), orientation="xz", ) grid.local.y = -10 scene.add(grid) spheres = [ ( (0, 0, -7.5), (0, 0.65, 0, 1), gfx.sphere_geometry(4.5, phi_length=np.pi * 1.5), ), ((0, 0, 7.5), (1, 1, 1, 1), gfx.sphere_geometry(4)), ( (15, 0, -7.5), (1, 0.3, 0.3, 1), gfx.sphere_geometry(4, theta_start=np.pi * 0.25, theta_length=np.pi * 0.50), ), ( (15, 0, 7.5), (0.35, 0, 0, 1), gfx.sphere_geometry(5, width_segments=6), ), ((-15, 0, -7.5), (1, 1, 0.75, 1), gfx.sphere_geometry(7)), ((-15, 0, 7.5), (1, 1, 0.75, 1), gfx.sphere_geometry(5, height_segments=8)), ] for pos, color, geometry in spheres: material = gfx.MeshPhongMaterial(color=color, flat_shading=True) wobject = gfx.Mesh(geometry, material) wobject.local.position = pos scene.add(wobject) camera = gfx.PerspectiveCamera(70, 16 / 9) camera.show_object(scene, (-1, -1, -1), up=(0, 1, 0)) scene.add(camera.add(gfx.DirectionalLight())) scene.add(gfx.AmbientLight()) controller = gfx.OrbitController(camera, register_events=renderer) if __name__ == "__main__": canvas.request_draw(lambda: renderer.render(scene, camera)) loop.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.401 seconds) .. _sphx_glr_download__gallery_feature_demo_spheres.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: spheres.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: spheres.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: spheres.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_ .. only:: html Interactive example ------------------- Try this example in your browser using Pyodide. Might not work with all examples and all devices. Check the output and your browser's console for details. .. raw:: html