In [12]:
import brushcue
import numpy as np
from IPython.display import Image, display
START_WAVELENGTH = 400
END_WAVELENGTH = 750
OUTPUT_FILE = "/home/dito/dev/monorepo/writing/graphics/chapters/color-formats/assets/wavelength_visualization.png"
painter = brushcue.Painter.new()
ctx = brushcue.Context()
for step, wavelength in enumerate(np.arange(START_WAVELENGTH, END_WAVELENGTH, 0.1)):
wavelength_color = brushcue.ProfiledColor.from_wavelength_nm(wavelength)
render_style = brushcue.RenderStyle.fill_only(
brushcue.Fill.solid(wavelength_color),
)
offset = wavelength - START_WAVELENGTH
painter = painter.add_rectangle_with_render_style(
brushcue.Point2f.from_components(offset, 0),
brushcue.Vector2f.from_components(1, 50),
0,
render_style,
brushcue.Transform2.to_list(brushcue.Transform2.identity())
)
composition = brushcue.Composition.painter(painter)
output_bytes = composition.execute(ctx).to_image_bytes(ctx)
with open(OUTPUT_FILE, "wb") as file:
file.write(output_bytes)
In [ ]:
display(Image(output_bytes))
In [2]: