In [ ]:
import json
import pathlib
import brushcue
from IPython.display import Image, display
OUTPUT_ROOT = "/home/dito/dev/monorepo/writing/graphics/chapters/color-modifications/assets/temperature/lights"
light_sources = [
("candle_flame", 1900),
("sunrise_sunset", 2500),
("incandescent_tungsten_bulb", 3000),
("warm_white_led", 2850),
("halogen_lamp", 3200),
("neutral_white_led", 4000),
("fluorescent_office_lighting", 4500),
("midday_sunlight", 5500),
("electronic_flash_studio_daylight", 5600),
("overcast_daylight", 6500),
("blue_sky_open_shade", 8000),
]
ctx = brushcue.Context()
for name, kelvin in light_sources:
blackbody_color = brushcue.ProfiledColor.blackbody(kelvin)
painter = brushcue.Painter.new()
render_style = brushcue.RenderStyle.brush_and_fill(
brushcue.Brush.solid(brushcue.ProfiledColor.from_rgba_srgb(brushcue.RGBAColor.from_components(0, 0, 0, 1)), 5),
brushcue.Fill.solid(blackbody_color)
)
painter = painter.add_ellipse_with_render_style(
brushcue.Point2f.from_components(0, 0),
brushcue.Vector2f.from_components(1000, 1000),
0,
render_style,
brushcue.Transform2.identity().to_list()
)
composition = brushcue.Composition.painter(painter)
result = composition.execute(ctx).to_image_bytes(ctx)
output_image_path = pathlib.Path(OUTPUT_ROOT).joinpath(f"{name}.png")
with open(output_image_path, "wb") as f:
f.write(result)
output_json_path = pathlib.Path(OUTPUT_ROOT).joinpath(f"{name}.json")
rgba = blackbody_color.to_rgb_encoded_with_color_profile(brushcue.ColorProfile.srgb()).execute(ctx)
rgba_json = {
"r": rgba[0],
"g": rgba[1],
"b": rgba[2],
"a": rgba[3]
}
with open(output_json_path, "w") as f:
json.dump(rgba_json, f)
In [11]:
blackbody_color.to_rgb_encoded_with_color_profile(brushcue.ColorProfile.srgb()).execute(ctx)
Out[11]:
(0.8924762010574341, 1.0, 1.0, 1.0)
In [2]: