.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/introductory/light_basic.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_introductory_light_basic.py: Lights ====== Simple light example. This example shows a cube with MeshPhongMaterial illuminated by a point light and a directional light. .. GENERATED FROM PYTHON SOURCE LINES 9-64 .. image-sg:: /_gallery/introductory/images/sphx_glr_light_basic_001.webp :alt: light basic :srcset: /_gallery/introductory/images/sphx_glr_light_basic_001.webp :class: sphx-glr-single-img .. code-block:: Python import time import numpy as np from rendercanvas.auto import RenderCanvas, loop import pygfx as gfx import pylinalg as la renderer = gfx.renderers.WgpuRenderer(RenderCanvas()) scene = gfx.Scene() cube = gfx.Mesh( gfx.box_geometry(20, 20, 20), gfx.MeshPhongMaterial(), ) cube.local.rotation = la.quat_from_euler((np.pi / 6, np.pi / 6), order="XY") scene.add(cube) light = gfx.DirectionalLight("#0040ff", 3) light.local.x = 15 light.local.y = 20 scene.add(light.add(gfx.DirectionalLightHelper(10))) light2 = gfx.PointLight("#ffaa00", 300, decay=2) # 300 candela light2.local.x = -15 light2.local.y = 20 scene.add(light2.add(gfx.PointLightHelper())) scene.add(gfx.AmbientLight("#fff", 0.2)) camera = gfx.PerspectiveCamera(70, 16 / 9) camera.show_object(cube, scale=1.5) controller = gfx.OrbitController(camera, register_events=renderer) def animate(): t = time.time() * 0.1 scale = 30 light2.local.position = ( np.cos(t) * np.cos(3 * t) * scale, np.cos(3 * t) * np.sin(t) * scale, np.sin(3 * t) * scale, ) renderer.render(scene, camera) renderer.request_draw() if __name__ == "__main__": renderer.request_draw(animate) loop.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.552 seconds) .. _sphx_glr_download__gallery_introductory_light_basic.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: light_basic.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: light_basic.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: light_basic.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