Note
Go to the end to download the full example code.
Additive Blending
This example draws overlapping circles of reference colors with additive blending.

import numpy as np
from rendercanvas.auto import RenderCanvas, loop
import pygfx as gfx
colors = ["#ff0000", "#00ff00", "#0000ff"]
distance_from_center = 0.5
canvas = RenderCanvas()
renderer = gfx.WgpuRenderer(canvas, gamma_correction=1.0)
camera = gfx.OrthographicCamera()
camera.show_rect(-2, 2, -2, 2)
scene = gfx.Scene()
plane = gfx.sphere_geometry(height_segments=64)
N = len(colors)
initial_angle = np.pi / 2
for i, color in enumerate(colors):
angle = -2 * np.pi * i / N + initial_angle
x = distance_from_center * np.cos(angle)
y = distance_from_center * np.sin(angle)
m = gfx.Mesh(
plane,
gfx.MeshBasicMaterial(
color=color,
alpha_mode="add",
),
)
m.local.x = x
m.local.y = y
scene.add(m)
canvas.request_draw(lambda: renderer.render(scene, camera))
if __name__ == "__main__":
print(__doc__)
loop.run()
Total running time of the script: (0 minutes 0.189 seconds)
Gallery generated by Sphinx-Gallery
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.