.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/validation/validate_color.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_color.py: Reference Color =============== This example draws squares of reference colors. These can be compared to similar output from e.g. Matplotlib. .. GENERATED FROM PYTHON SOURCE LINES 8-54 .. image-sg:: /_gallery/validation/images/sphx_glr_validate_color_001.webp :alt: validate color :srcset: /_gallery/validation/images/sphx_glr_validate_color_001.webp :class: sphx-glr-single-img .. code-block:: Python from rendercanvas.auto import RenderCanvas, loop import pygfx as gfx colors1 = ["#ff0000", "#770000", "#00ff00", "#007700", "#0000ff", "#000077"] colors2 = ["#000000", "#333333", "#666666", "#999999", "#cccccc", "#ffffff"] canvas = RenderCanvas() renderer = gfx.WgpuRenderer(canvas, gamma_correction=1.0) camera = gfx.OrthographicCamera() camera.show_rect(-0.5, 5.5, 0, 2) scene = gfx.Scene() plane = gfx.plane_geometry() for i, color in enumerate(colors1): m = gfx.Mesh(plane, gfx.MeshBasicMaterial(color=color)) m.local.x = i m.local.y = 0 scene.add(m) for i, color in enumerate(colors2): m = gfx.Mesh(plane, gfx.MeshBasicMaterial(color=color)) m.local.x = i m.local.y = 1 scene.add(m) canvas.request_draw(lambda: renderer.render(scene, camera)) # # Code to show the same scene in MPL # import matplotlib.pyplot as plt # from matplotlib.patches import Rectangle # fig, ax = plt.subplots() # ax.set_facecolor("k") # plt.xlim([0, 6]) # plt.ylim([-1, 3]) # for i, color in enumerate(colors1): # ax.add_patch(Rectangle((i, 0), 1, 1, facecolor=color)) # for i, color in enumerate(colors2): # ax.add_patch(Rectangle((i, 1), 1, 1, facecolor=color)) # fig.show() if __name__ == "__main__": print(__doc__) loop.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.162 seconds) .. _sphx_glr_download__gallery_validation_validate_color.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: validate_color.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: validate_color.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: validate_color.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