.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/feature_demo/point_sprites.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_point_sprites.py: Simulating grass with point sprites =================================== This example simulates a grassy plane, using a technique that early 3D games used a lot. We create an image with green stripes. Than place a couple thousand of these in a plane, using a Points object. .. GENERATED FROM PYTHON SOURCE LINES 9-42 .. image-sg:: /_gallery/feature_demo/images/sphx_glr_point_sprites_001.webp :alt: point sprites :srcset: /_gallery/feature_demo/images/sphx_glr_point_sprites_001.webp :class: sphx-glr-single-img .. code-block:: Python import numpy as np import pygfx as gfx # Create image of 'grass' (luminance + alpha) im = np.zeros((20, 20, 2), np.uint8) im[:, :, 0] = 255 lengths = np.abs(np.random.normal(1, im.shape[1], (im.shape[0],)).astype(np.int32)) for i, length in enumerate(lengths): im[:length, i, 1] = 100 if i % 2 else 20 # alternate high/low alpha # Create random positions positions = np.random.uniform(0, 100, size=(2000, 3)).astype(np.float32) positions[:, 1] = 0 # Create point sprites grasses = gfx.Points( gfx.Geometry(positions=positions), gfx.PointsSpriteMaterial( color="#8F0", sprite=gfx.Texture(im, dim=2), size=3, size_space="world" ), ) # Use a camera that is more inside the field, looking from above camera = gfx.PerspectiveCamera() camera.show_object(grasses, view_dir=(1, -1, 1), scale=0.25) if __name__ == "__main__": disp = gfx.Display(camera=camera) disp.show(grasses) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.599 seconds) .. _sphx_glr_download__gallery_feature_demo_point_sprites.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: point_sprites.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: point_sprites.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: point_sprites.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