In [1]:
import json
from pathlib import Path
import brushcue

ctx = brushcue.Context()

COLOR_1 = brushcue.ProfiledColor.from_rgba_srgb(
    brushcue.RGBAColor.from_components(74/255, 56/255, 140/255, 1.0)
)
COLOR_2 = brushcue.ProfiledColor.from_rgba_srgb(
    brushcue.RGBAColor.from_components(23/255, 179/255, 18/255, 1.0)
)
COLOR_3 = brushcue.ProfiledColor.from_rgba_srgb(
    brushcue.RGBAColor.from_components(93/255, 93/255, 93/255, 1.0)
)
COLOR_4 = brushcue.ProfiledColor.from_rgba_srgb(
    brushcue.RGBAColor.from_components(71/255, 32/255, 37/255, 1.0)
)

BASE_PATH = "/Users/dito/dev/graphics-book/writing/graphics/chapters/color-modifications/assets"

def create_swatch(profiled_color: brushcue.ProfiledColor, output_file_path: str):
    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.0, 0.0, 1.0)
            ),
            2
        ),
        brushcue.Fill.solid(
            profiled_color
        )
    )
    painter = painter.add_ellipse_with_render_style(
        brushcue.Point2f.from_components(0.0, 0.0),
        brushcue.Vector2f.from_components(400.0, 400.0),
        0,
        render_style,
        brushcue.Transform2.to_list(brushcue.Transform2.identity())
    )
    composition_painter = brushcue.Composition.painter(painter)
    result = composition_painter.execute(ctx).to_image_bytes(ctx)
    with open(output_file_path, "wb") as output_file:
        output_file.write(result)
    json_filename = str(Path(output_file_path).with_suffix(".json"))
    actualized_color_oklaba = profiled_color.to_ok_lab_a().execute(ctx)
    actualized_color_rgba_srgb = profiled_color.to_rgb_encoded_with_color_profile(
        brushcue.ColorProfile.srgb()
    ).execute(ctx)
    actualized_color_rgba_srgb_linear = profiled_color.to_rgb_linear_with_color_profile(
        brushcue.ColorProfile.srgb()
    ).execute(ctx)
    json_data = {
        "oklaba": actualized_color_oklaba,
        "rgba_srgb": actualized_color_rgba_srgb,
        "rgba_srgb_linear": actualized_color_rgba_srgb_linear
    }
    with open(json_filename, "w") as output_file:
        json.dump(json_data, output_file, indent=4)

Shared¶

In [2]:
SHARED_BASE_PATH = BASE_PATH + "/shared"

create_swatch(COLOR_1, SHARED_BASE_PATH + "/color-1.png")
create_swatch(COLOR_2, SHARED_BASE_PATH + "/color-2.png")
create_swatch(COLOR_3, SHARED_BASE_PATH + "/color-3.png")
create_swatch(COLOR_4, SHARED_BASE_PATH + "/color-4.png")

BRIGHTNESS¶

In [3]:
BRIGHTNESS_BASE_PATH = BASE_PATH + "/brightness"

BRIGHTNESS_COLOR_1 = COLOR_1.brightness_adjust(0.3)
BRIGHTNESS_COLOR_2 = COLOR_2.brightness_adjust(-0.15)
BRIGHTNESS_COLOR_3 = COLOR_3.brightness_adjust(0.2)
BRIGHTNESS_COLOR_4 = COLOR_4.brightness_adjust(-0.2)
create_swatch(BRIGHTNESS_COLOR_1, BRIGHTNESS_BASE_PATH + "/color-1-brightness-0.3.png")
create_swatch(BRIGHTNESS_COLOR_2, BRIGHTNESS_BASE_PATH + "/color-2-brightness-neg0.15.png")
create_swatch(BRIGHTNESS_COLOR_3, BRIGHTNESS_BASE_PATH + "/color-3-brightness-0.2.png")
create_swatch(BRIGHTNESS_COLOR_4, BRIGHTNESS_BASE_PATH + "/color-4-brightness-neg0.2.png")

Exposure¶

In [7]:
EXPOSURE_BASE_PATH = BASE_PATH + "/exposure"

EXPOSURE_COLOR_1 = COLOR_1.exposure_adjust(2)
EXPOSURE_COLOR_2 = COLOR_2.exposure_adjust(-2)
EXPOSURE_COLOR_3 = COLOR_3.exposure_adjust(1)
EXPOSURE_COLOR_4 = COLOR_4.exposure_adjust(-1)
create_swatch(EXPOSURE_COLOR_1, EXPOSURE_BASE_PATH + "/color-1-exposure-2.png")
create_swatch(EXPOSURE_COLOR_2, EXPOSURE_BASE_PATH + "/color-2-exposure-neg2.png")
create_swatch(EXPOSURE_COLOR_3, EXPOSURE_BASE_PATH + "/color-3-exposure-1.png")
create_swatch(EXPOSURE_COLOR_4, EXPOSURE_BASE_PATH + "/color-4-exposure-neg1.png")
In [ ]: