Table of Contents

Class NoisePaint

Namespace
Egami.Drawing
Assembly
Egami.Drawing.dll

Procedural noise as a paint. Fractal(float, float, int, int, Size?) and Turbulence(float, float, int, int, Size?) follow SVG 1.1's feTurbulence step by step (its random table, lattice and gradients), so the pixels match Skia's noise shaders and browsers within rounding; Simplex(float, int, int, Size?) is smoother and can tile. Each of the four channels is its own noise, straight alpha included. The noise lives in paint coordinates: it scales and turns with the canvas transform and LocalMatrix.

public sealed record NoisePaint : Paint, ITextPaint, IEquatable<Paint>, IEquatable<NoisePaint>
Inheritance
NoisePaint
Implements
Inherited Members

Examples

using (RasterCanvas<Rgba8> canvas = raster.CreateCanvas())
{
    // SVG's feTurbulence fractal noise, stitched so a 128-pixel tile repeats without a seam, made gray by a color matrix.
    Paint stone = NoisePaint.Fractal(0.03f, 0.03f, octaves: 5, seed: 7, tileSize: new Size(128, 128))
        .WithColorMatrix(new ColorMatrix([0.3f, 0.6f, 0.1f, 0, 0, 0.3f, 0.6f, 0.1f, 0, 0, 0.3f, 0.6f, 0.1f, 0, 0, 0, 0, 0, 0, 1]));
    canvas.DrawPaint(stone);

    // Smooth simplex noise as a soft overlay.
    canvas.DrawPaint(NoisePaint.Simplex(0.01f, octaves: 3) with { BlendMode = BlendMode.Overlay, Opacity = 0.5f });
}

Fields

MaxOctaves

The most octaves a noise paint sums.

public const int MaxOctaves = 32

Field Value

int

Properties

BaseFrequencyX

Gets the horizontal frequency of the first octave, in cycles per paint unit.

public float BaseFrequencyX { get; }

Property Value

float

BaseFrequencyY

Gets the vertical frequency of the first octave.

public float BaseFrequencyY { get; }

Property Value

float

Kind

Gets the kind of noise.

public NoisePaintKind Kind { get; }

Property Value

NoisePaintKind

Octaves

Gets the number of octaves summed, each twice the frequency and half the amplitude of the one before; 0 draws transparent black.

public int Octaves { get; }

Property Value

int

Seed

Gets the seed of the random tables.

public int Seed { get; }

Property Value

int

TileSize

Gets the size of the tile the noise repeats over, from the paint origin, or null for noise that never repeats. For the SVG kinds this is feTurbulence's stitching (the frequencies are adjusted so the tile's edges meet); for simplex noise the tile is exact.

public Size? TileSize { get; }

Property Value

Size?

Methods

Fractal(float, float, int, int, Size?)

Returns SVG feTurbulence's fractalNoise.

public static NoisePaint Fractal(float baseFrequencyX, float baseFrequencyY, int octaves = 1, int seed = 0, Size? tileSize = null)

Parameters

baseFrequencyX float

The horizontal frequency, as SVG's baseFrequency.

baseFrequencyY float

The vertical frequency.

octaves int

The number of octaves, as SVG's numOctaves, from 0 to 32.

seed int

The seed.

tileSize Size?

The tile to stitch to, as SVG's stitchTiles over a tile of this size; null for none.

Returns

NoisePaint

The paint.

Exceptions

ArgumentOutOfRangeException

A frequency is negative or not finite, the octaves are outside 0 to 32, or the tile is empty.

Simplex(float, int, int, Size?)

Returns simplex noise: each channel a half plus half the octaves' sum, scaled so it stays within 0 to 1. With a tile size it repeats exactly over that tile, made by running the noise around a torus.

public static NoisePaint Simplex(float frequency, int octaves = 1, int seed = 0, Size? tileSize = null)

Parameters

frequency float

The frequency of the first octave, in cycles per paint unit.

octaves int

The number of octaves, from 0 to 32.

seed int

The seed of the gradient table.

tileSize Size?

The tile it repeats over; null for none.

Returns

NoisePaint

The paint.

Exceptions

ArgumentOutOfRangeException

The frequency is negative or not finite, the octaves are outside 0 to 32, or the tile is empty.

Turbulence(float, float, int, int, Size?)

Returns SVG feTurbulence's turbulence.

public static NoisePaint Turbulence(float baseFrequencyX, float baseFrequencyY, int octaves = 1, int seed = 0, Size? tileSize = null)

Parameters

baseFrequencyX float

The horizontal frequency.

baseFrequencyY float

The vertical frequency.

octaves int

The number of octaves, from 0 to 32.

seed int

The seed.

tileSize Size?

The tile to stitch to; null for none.

Returns

NoisePaint

The paint.

Exceptions

ArgumentOutOfRangeException

A frequency is negative or not finite, the octaves are outside 0 to 32, or the tile is empty.