Atelier

AtelierPattern

Repeatable fills that never show a seam.

Fill SVG shapes with repeating tiles. Pattern provides twenty-four motifs as native <pattern> elements, so one definition can fill several shapes in a document.

Dots, triangles and seigaiha. Each surface repeats a single SVG pattern tile.

Features

  • Tiles repeat across a surface
    Geometry joins at tile boundaries, including the irregular motifs generated from a seed.
  • A pattern is a value
    No document is needed to build one, and building one mutates nothing. Prepare a tile ahead of time, test it on its own, attach it when you have a document.
  • The colour is inherited
    A tile paints with currentColor over a transparent background, so one definition serves every tint and follows the theme it sits in.

Fill a shape

use Atelier\Pattern\Pattern;
use Atelier\Pattern\PatternRegistry;
use Atelier\Svg\Document;
use Atelier\Svg\Dumper\CompactXmlDumper;
use Atelier\Svg\Element\Shape\RectElement;

$dots = Pattern::dots(spacing: 14, radius: 2.2)->withColor('#f4715c');
$document = Document::create(400, 240);
(new PatternRegistry($dots))->attachTo($document);

$surface = new RectElement();
$surface->setWidth('400')->setHeight('240')->setAttribute('fill', $dots->fill());
$document->getRootElement()?->appendChild($surface);

echo (new CompactXmlDumper())->dump($document);

Identifiers are derived from geometry and style. Identical tiles share one definition when registered together. Use withId() to supply an explicit identifier.

Browse the twenty-four illustrated tiles for geometric and seeded motifs. For a drawing that varies across a fixed area, use Field.

Set the style

use Atelier\Pattern\Pattern;

$stripes = Pattern::stripes(spacing: 12, thickness: 4)
    ->withColor('#c0392b')
    ->withOpacity(0.4)
    ->withAngle(45);

Style methods return a new pattern. withAngle() rotates the pattern through patternTransform. The default colour is currentColor and the background is transparent.

See Getting started for seeded output, identifier handling, and geometry validation.

Source and requirements

Requires PHP 8.3 or later and Atelier SVG.

View Pattern on GitHub.