Fills, gradients and outlines#
Purpose and concepts#
Colors are HEX strings or rgb/hsv/oklch values. HEX’s last two digits encode alpha: #ffffff90 is about 56.47% opacity. Color alpha multiplies object, stroke and ancestor-group opacity.
Minimal complete example#
Run this file directly with laymesh validate or laymesh render; it contains its own canvas and required definitions.
# Minimal complete example: rgbpage=canvas(size=(100mm,75mm),background="#ffffff")page.add(rect(size=(60mm,30mm),fill=rgb(255,80,40,alpha=0.6)),offset=(10mm,10mm))# Minimal complete example: rgbpage=canvas(size=(100mm,75mm),background="#ffffff")page.add(rect(size=(60mm,30mm),fill=rgb(255,80,40,alpha=0.6)),offset=(10mm,10mm))Preview
Dependencies
examples/manual/rgb.lay
Parameters and default behavior#
Unitless geometry uses the canvas unit; unitless type and stroke sizes use pt. Explicit call parameters override inherited/theme defaults. The linked interface reference lists accepted types, choices and defaults per parameter.
Composition#
Use colors in fills, text, strokes, gradient stops and chart palettes. linear_gradient and radial_gradient use normalized layout-box coordinates. hatch uses physical spacing; image_fill fits an image inside a shape.
paint = linear_gradient(start=(0, 0), end=(1, 1), stops=[(0, "#f8cf7b"), (0.5, "#ed8770"), (1, "#8f5fa5")])page.add(rect(size=(75 mm, 42 mm), border_radius=5 mm, fill=paint), target=page.top_left, offset=(22 mm, 27 mm))# Gallery: shapes / linear-gradientpage = canvas(name="Linear gradient", size=(120 mm, 80 mm), background="#f7f9fc")font = "DejaVu Sans"heading = text(content="Linear gradient", font_family=font, font_size=14 pt, color="#203864")page.add(heading, target=page.top_left, offset=(7 mm, 5 mm))# BEGIN DEMOpaint = linear_gradient(start=(0, 0), end=(1, 1), stops=[(0, "#f8cf7b"), (0.5, "#ed8770"), (1, "#8f5fa5")])page.add(rect(size=(75 mm, 42 mm), border_radius=5 mm, fill=paint), target=page.top_left, offset=(22 mm, 27 mm))# END DEMOPreview
Dependencies
examples/gallery/shapes/linear-gradient.lay
Common errors and limits#
RGB is 0–255; HSV S/V and OKLCH L are 0–1; C is nonnegative and alpha is 0–1. Invalid or nonfinite values error. Out-of-gamut OKLCH reduces chroma with a mapping notice. HSL/CMYK are not supported.
Individual functions#
linear_gradient#
Create linear-gradient paint with stops in 0–1 and start/end normalized to material bounds. Color alpha multiplies stop opacity.
Returns: paint
Required inputs: stops.
Minimal complete source · Composition source · All parameters
radial_gradient#
Create radial-gradient paint with center/radius relative to bounds. Reuse the paint across different shapes; placement dimensions determine final rendering.
Returns: paint
Required inputs: stops.
Minimal complete source · Composition source · All parameters
hatch#
Create slash/cross/dots pattern paint. spacing and line_width are physical dimensions; the pattern is confined to the material fill region.
Returns: paint
Minimal complete source · Composition source · All parameters
image_fill#
Use a local image as paint inside a shape, with fit controlling adaptation. Unlike image material, paint is confined to the shape outline, including rounded rectangles.
Returns: paint
Required inputs: src.
Minimal complete source · Composition source · All parameters
rgb#
Create a RGB color with alpha=0–1.
Returns: color
Required inputs: r, g, b.
Minimal complete source · Composition source · All parameters
hsv#
Create a HSV color with alpha=0–1.
Returns: color
Required inputs: h, s, v.
Minimal complete source · Composition source · All parameters
oklch#
Create a OKLCH color with alpha=0–1.
Returns: color
Required inputs: l, c, h.
Minimal complete source · Composition source · All parameters
Detailed behavior and further examples#
Parameters#
| Parameter | Purpose | Default or requirement |
|---|---|---|
fill |
Color or gradient | Also accepts none |
border_* / line_* |
Closed/open stroke settings | Defaults and choices in the shared reference |
Common usage#
fill accepts colors, none, gradients, hatch and image_fill paint. Use border_* for closed outlines and line_* for open strokes; LCSS classes reuse settings. outline(...) is removed. Gradient strokes are not implemented.
Limits and related topics#
Image import and cropping · Text and fonts · Resource paths · Mathematical formulas · Shapes and paths
RGB, HSV, OKLCH and alpha#
Colors accept #RGB/#RGBA/#RRGGBB/#RRGGBBAA with trailing alpha, e.g. #ffffff90 means 144/255 alpha. DSL constructors include rgb(255,80,40,alpha=0.6), hsv(200deg,0.7,0.8,alpha=0.6), and oklch(0.7,0.15,200deg,alpha=0.6). Strings and LCSS accept space-separated functions with / alpha, e.g. oklch(0.7 0.15 200 / 0.6). HSV is a LayMesh extension; CMYK is not supported.
RGB channels range from 0 to 255; HSV saturation/value and OKLCH lightness range from 0 to 1. OKLCH chroma is nonnegative; alpha ranges from 0 to 1. Hue accepts deg/rad or unitless degrees. OKLCH retains source channels and uses deterministic constant-lightness/hue chroma reduction with 48 binary-search iterations to map to sRGB. The editor reports gamut mapping; CLI, WASM and exports use identical results.
Color alpha multiplies drawing opacity. Fills, strokes, text, gradients and color scales share the rule. Color lists retain linear RGB channel interpolation and interpolate alpha as well.

