.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/feature_demo/cylinder.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_cylinder.py: Types of Cylinders ================== Example showing different types of geometric cylinders. .. GENERATED FROM PYTHON SOURCE LINES 7-83 .. image-sg:: /_gallery/feature_demo/images/sphx_glr_cylinder_001.webp :alt: cylinder :srcset: /_gallery/feature_demo/images/sphx_glr_cylinder_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() cylinders = [ ((0, 0, -32.5), (0, 0.65, 0, 1), gfx.cylinder_geometry(10, 10, height=25)), ( (30, 0, 25), (1, 0.3, 0.3, 1), gfx.cylinder_geometry( 10, 10, height=12, theta_start=np.pi * 1.3, theta_length=np.pi * 1.5, open_ended=True, ), ), ( (-50, 0, 0), (0, 0, 0.65, 1), gfx.cylinder_geometry( 20, 12, radial_segments=3, height_segments=4, height=10, open_ended=True ), ), ((50, 0, -10), (1, 1, 0.75, 1), gfx.cylinder_geometry(1.5, 1.5, height=20)), ((50, 0, 5), (1, 1, 0.75, 1), gfx.cylinder_geometry(4, 0.0, height=10)), ] for pos, color, geometry in cylinders: material = gfx.MeshPhongMaterial(color=color) wobject = gfx.Mesh(geometry, material) wobject.local.position = pos scene.add(wobject) material = gfx.MeshNormalLinesMaterial(color=color) wobject = gfx.Mesh(geometry, material) wobject.local.position = pos wobject.cast_shadow = True scene.add(wobject) camera = gfx.PerspectiveCamera(70, 16 / 9) camera.local.position = (50, 50, 50) camera.show_pos((0, 0, 0)) controller = gfx.OrbitController(camera, register_events=renderer) scene.add(gfx.AmbientLight()) light = gfx.PointLight() light.local.position = (0, 70, 0) light.add(gfx.PointLightHelper()) light.cast_shadow = True # since we are shadow mapping open meshes # disable front face culling to render backfaces to shadow maps # and set bias to avoid shadow acne light.shadow.cull_mode = "none" light.shadow.bias = 0.00001 scene.add(light) ground = gfx.Mesh( gfx.box_geometry(1000, 1, 1000), gfx.MeshPhongMaterial(), ) ground.local.y = -40 ground.receive_shadow = True scene.add(ground) 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.803 seconds) .. _sphx_glr_download__gallery_feature_demo_cylinder.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: cylinder.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: cylinder.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: cylinder.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