In [12]:
import brushcue
OUTPUT_PATH = "/Users/dito/dev/graphics-book/writing/graphics/chapters/color-modifications/assets/exposure"
ctx = brushcue.Context()
start_color = brushcue.ProfiledColor.from_rgba_srgb(
brushcue.RGBAColor.from_components(3/255, 54/255, 16/255, 1.0)
)
def create_gradient(output_path: str, step):
painter = brushcue.Painter.new()
total_number_of_steps = 1000
for i in range(0, total_number_of_steps):
percent_done = i / (total_number_of_steps - 1)
current_color = step(start_color, percent_done)
render_style = brushcue.RenderStyle.fill_only(
brushcue.Fill.solid(current_color)
)
painter = painter.add_rectangle_with_render_style(
brushcue.Point2f.from_components(i, 0),
brushcue.Vector2f.from_components(1, 200),
0,
render_style,
brushcue.Transform2.to_list(brushcue.Transform2.identity())
)
composition = brushcue.Composition.painter(painter)
image_bytes = composition.execute(ctx).to_image_bytes(ctx)
with open(output_path, "wb") as f:
f.write(image_bytes)
In [13]:
def brightness_step(profiled_color: brushcue.ProfiledColor, percent_done: float) -> brushcue.ProfiledColor:
return profiled_color.brightness_adjust(offset=0.8 * percent_done)
create_gradient(f"{OUTPUT_PATH}/brightness-gradient.png", brightness_step)
In [14]:
def exposure_step(profiled_color: brushcue.ProfiledColor, percent_done: float) -> brushcue.ProfiledColor:
return profiled_color.exposure_adjust(7 * percent_done)
create_gradient(f"{OUTPUT_PATH}/exposure-gradient.png", exposure_step)