.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/validation/validate_grid1.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_validation_validate_grid1.py: Validate the grid ================= Show a bunch of grids touching various grid-cases. .. GENERATED FROM PYTHON SOURCE LINES 8-128 .. image-sg:: /_gallery/validation/images/sphx_glr_validate_grid1_001.webp :alt: validate grid1 :srcset: /_gallery/validation/images/sphx_glr_validate_grid1_001.webp :class: sphx-glr-single-img .. code-block:: Python from rendercanvas.auto import RenderCanvas, loop import pygfx as gfx canvas = RenderCanvas() renderer = gfx.renderers.WgpuRenderer(canvas) scene = gfx.Scene() scene.add(gfx.Background.from_color("#fff")) # An inf grid at the floor grid0 = gfx.Grid( None, gfx.GridMaterial( major_step=1, minor_step=0.1, thickness_space="world", axis_thickness=0.1, major_thickness=0.02, minor_thickness=0.002, infinite=True, ), orientation="xz", ) # A grid oriented in yz, showing major and minor ticks grid1 = gfx.Grid( None, gfx.GridMaterial( major_step=1, minor_step=0.2, thickness_space="screen", major_thickness=2, minor_thickness=1, major_color="#aa0", minor_color="#aa0", infinite=False, ), orientation="yz", ) # A grid oriented in xy, showing how small offsets (i.e. float errors are ok) grid2 = gfx.Grid( None, gfx.GridMaterial( major_step=(0.9999, 1.0001), minor_step=0.2, thickness_space="screen", major_thickness=2, minor_thickness=0.5, major_color="#a00", minor_color="#a00", infinite=False, ), orientation="xy", ) # A grid with weird sampling grid3 = gfx.Grid( None, gfx.GridMaterial( major_step=0.275, minor_step=0.0, thickness_space="screen", major_thickness=3, minor_thickness=0.75, major_color="#0a0", minor_color="#0a0", infinite=False, ), orientation="xy", ) grid3.local.x = 1 # Shifted and scaled grid4 = gfx.Grid( None, gfx.GridMaterial( major_step=0.275, minor_step=0.0, thickness_space="screen", major_thickness=3, minor_thickness=0.75, major_color="#00a", minor_color="#00a", infinite=False, ), orientation="xy", ) grid4.local.x = 2 grid4.local.y = 0.2 grid4.local.scale = 0.7, 1, 2 scene.add(grid0, grid1, grid2, grid3, grid4) # Show box at (0.5, 0.5, 0.5) to show where the positive axii are cube = gfx.Mesh( gfx.sphere_geometry(0.1), gfx.MeshBasicMaterial(color="#000"), ) cube.local.position = 0.5, 0.5, 0.5 scene.add(cube) # camera = gfx.OrthographicCamera(5, 5) camera = gfx.PerspectiveCamera() camera.local.position = (3.75, 1.5, 1.5) camera.show_pos((1, 1, 0)) controller = gfx.OrbitController(camera, register_events=renderer) canvas.request_draw(lambda: renderer.render(scene, camera)) if __name__ == "__main__": print(__doc__) loop.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.430 seconds) .. _sphx_glr_download__gallery_validation_validate_grid1.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: validate_grid1.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: validate_grid1.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: validate_grid1.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