@svg-filter
An SVG filter for the filter and backdrop-filter properties.
A short form covers the common noise displacement effect; any filter can be written out in full.
Syntax
- @svg-filter(<frequency>, <scale> [, <octave>, <seed>])
- @svg-filter(blur=<n>, erode=<n>, dilate=<n>)
- @svg-filter(<filter-body>)
- @svg-filter(<filter>...</filter>)
- frequency
baseFrequencyof afeTurbulencewith fractal noise. Two values set x and y separately.- scale
scaleof thefeDisplacementMapdriven by that noise.- octave, seed
numOctavesandseedof the noise. The seed defaults to the doodle's seed.- blur, erode, dilate
-
feGaussianBlurandfeMorphologysteps. In the comma form the noise displaces the original element, so these are lost next to ascale; to combine them use the body form,blur: 3; frequency: .02; scale: 30;.
Arguments may be positional or named, scale=30. The noise seed defaults to the doodle’s
seed. The full form takes the children of a
<filter> in the SVG syntax, or the XML.
The filter is mounted inside the component and referenced by id.
@filter is an older name.
In the body, the short-form names are declarations, frequency: .02; scale: 30;, and can sit
between primitives; scale then displaces the output of the step before it.
region sets how far the filter may draw outside the element, x [y] / width [height]
or one percentage for every side. It defaults to 20% when any short-form name is used.
Examples
@grid: 1 / 60vmin;
background: #000;
border-radius: 50%;
filter: @svg-filter(.02, 30); Named arguments:
@grid: 4 / 60vmin _10px;
background: #000;
filter: @svg-filter(frequency=.05, scale=15, octave=3); As a backdrop filter over the whole grid, with the | modifier of @grid:
@grid: 4 / 60vmin ^.85 _10px | @svg-filter(.015, 50);
border-radius: 50%;
background: #000; A filter written in full:
@grid: 1 / 60vmin;
background: #000;
border-radius: 50%;
filter: @svg-filter(
feTurbulence {
type: fractalNoise;
baseFrequency: .01 .5;
}
feDisplacementMap {
in: SourceGraphic;
scale: 50;
}
); Channels
A channels block in the body is a color matrix, an feColorMatrix.
Each declaration sets one output channel, r, g, b or a,
to a sum of input channels and a number, written like the an+b of @nth:
1 - r, .5g + .2, 2 * b. Channels not listed stay unchanged.
Every expression reads the original input, so r: b; b: r swaps red and blue.
Anything else, such as r * g or parentheses, is ignored with a warning.
Other declarations, such as in and result, go to the feColorMatrix.
@grid: 6 / 60vmin;
background: @p(#e6437d, #ebbf4d, #000);
filter: @svg-filter(
channels { r: b; b: r; }
); Blur, then sharpen the alpha so shapes that touch melt together:
@grid: 6 / 60vmin;
@size: @r(40%, 90%);
background: #000;
border-radius: 50%;
transform: translate(@r(-40%, 40%), @r(-40%, 40%));
:container {
filter: @svg-filter(
blur: 6;
channels { a: 20a - 8; }
);
}