LLumaGauge
Workflows

Coding workflows · Relative luminance contrast

03
Built around your work

A concrete starting point

Calculate relative-luminance contrast between two three-channel eight-bit RGB colors. Check black against white, equal colors and reversed arguments, rejecting non-integer or out-of-range channels without treating the ratio as a complete accessibility assessment.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Relative luminance contrast

A concrete starting point
def contrast_ratio(left, right):
    def luminance(rgb):
        if type(rgb) not in (list, tuple) or len(rgb) != 3:
            raise ValueError("rgb.container")
        rgb = tuple(rgb)
        if len(rgb) != 3 or any(type(c) is not int or not 0 <= c <= 255 for c in rgb):
            raise ValueError("rgb.channel")
        channels = [c / 255 for c in rgb]
        linear = [c / 12.92 if c <= 0.04045 else ((c + 0.055) / 1.055)**2.4
                  for c in channels]
        return sum(c * w for c, w in zip(linear, (0.2126, 0.7152, 0.0722)))
    a, b = sorted((luminance(left), luminance(right)))
    return (b + 0.05) / (a + 0.05)

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗