SVG noise filter — Part I
Introduction
What’s that noise?
Normally when we speak of “noise” we mean sound.
Today we will be speaking about “noise” in the context of graphics, and applying it to some SVG elements.
There is only one filter primitive available for applying noise to SVGs and that is
<feTurbulance/>Under the hood it uses the popular Perlin noise algorithm developed by Ken Perlin.
This produces a natural-looking noise effect and is commonly used to create graphics such as land, clouds, fire and water kind of like Captain Planet’s — earth, air, fire, water, (and heart?).
Base Frequency
feTurbulance requires a baseFrequency attribute.
<feTurbulance baseFrequency="<NUMBER> | <NUMBER NUMBER>"/>To put it simply, the input represents a “multiplier” for the noise algorithm.
The higher the baseFrequency, the more “noisy” your noise gets. If you supply a single number, this number will be used for both the x and y frequency.
Get codebro.io’s stories in your inbox
Join Medium for free to get updates from this writer.
Alternatively you can provide two numbers separated by a space representing x and y respectively.
Let’s make some noise
- Make an SVG.
<svg>
<rect width="100" height="100"/>
</svg>2. Add a filter element to it.
<svg>
<filter></filter>
<rect width="100" height="100"/>
</svg>3. Nest your filter primitive inside this and apply a base frequency.
<svg>
<filter>
<feTurbulance baseFrequency="0.05"/>
</filter>
<rect width="100" height="100"/>
</svg>4. Use an id to reference your filter primitive on whatever element you are trying to apply the noise to.
<svg>
<filter id="noise">
<feTurbulance baseFrequency="0.05"/>
</filter>
<rect filter="url(#noise)" width="100" height="100"/>
</svg>Right now we have simply added the noise over the top of our shape, in the next article we will merge it into our shape.
SVG noise filter series
Part I — Introduction — https://medium.com/@codebro/svg-noise-filter-45b5edbbc28d
Part II — Applying noise to shapes — https://medium.com/@codebro/svg-noise-filter-fd5a5edfba86
Part III — Bells and whistles — https://medium.com/@codebro/svg-noise-filter-f38a9327f66c
Part IV — Animating the noise — https://medium.com/@codebro/svg-noise-filter-bc6247ba4399
Part V — Thicc noise — https://medium.com/@codebro/svg-noise-filter-part-v-6836c8351c45








