aest 0.1.0
Collection of C++ utility libraries
Loading...
Searching...
No Matches
Random.cppm File Reference

Partition aest.colors:random: random colors drawn from a caller-supplied random bit generator. More...

#include <array>
#include <concepts>
#include <cstdint>
#include <random>
import aest.colors:space;

Go to the source code of this file.

Concepts

concept  aest::colors::RandomBitGenerator
 A uniform random bit generator whose every output bit is random: its range is a power of two, of at least 2^24.

Functions

template<RandomBitGenerator Generator>
constexpr float aest::colors::unit_float (Generator &generator)
 Draw a float uniformly distributed in [0, 1).
template<BoundedRGBSpace Space = SRGB, RandomBitGenerator Generator>
constexpr Space aest::colors::random_color (Generator &generator)
 A random opaque color, uniform over the channels of an encoded RGB space.
template<HueSpace Space = OKLCH, ColorType Color, RandomBitGenerator Generator>
requires ConvertibleTo<Space, Color> && ConvertibleTo<Color, Space>
constexpr Color aest::colors::random_hue (const Color &color, Generator &generator, In< Space > space={})
 A copy of a color with a random hue, keeping the rest.

Detailed Description

Partition aest.colors:random: random colors drawn from a caller-supplied random bit generator.

Author
Davide Pierotti

Definition in file Random.cppm.

Function Documentation

◆ random_color()

template<BoundedRGBSpace Space = SRGB, RandomBitGenerator Generator>
Space aest::colors::random_color ( Generator & generator)
constexprexport

A random opaque color, uniform over the channels of an encoded RGB space.

Each channel is drawn uniformly from [0, 1), red first. The draws are uniform in the encoding, not to the eye: random_hue() gives colors of an even lightness instead.

Template Parameters
SpaceThe bounded RGB space to draw in, SRGB by default
GeneratorThe random bit generator
Parameters
[in,out]generatorThe generator to draw from; it advances by three outputs
Returns
The random color, with alpha 1.

Definition at line 74 of file Random.cppm.

◆ random_hue()

template<HueSpace Space = OKLCH, ColorType Color, RandomBitGenerator Generator>
requires ConvertibleTo<Space, Color> && ConvertibleTo<Color, Space>
Color aest::colors::random_hue ( const Color & color,
Generator & generator,
In< Space > space = {} )
constexprexport

A copy of a color with a random hue, keeping the rest.

The color is converted to Space, its hue is replaced by one drawn uniformly from [0, 360) and it is converted back. In the default, OKLCH, the perceived lightness and chroma are kept, so every result looks as bright and as vivid as color: drawing from one base color gives a palette of even weight. The result may fall outside the gamut and clip when converted back. Gray colors have no hue and stay as they are.

Template Parameters
SpaceThe color space the hue is drawn in
ColorThe color type of the input and the result
GeneratorThe random bit generator
Parameters
[in]colorThe color whose hue to replace
[in,out]generatorThe generator to draw from; it advances by one output
[in]spaceThe working space, e.g. in<HSL>; OKLCH when omitted
Returns
The color with a random hue, and the alpha of color.

Definition at line 103 of file Random.cppm.

◆ unit_float()

template<RandomBitGenerator Generator>
float aest::colors::unit_float ( Generator & generator)
constexpr

Draw a float uniformly distributed in [0, 1).

std::uniform_real_distribution is not used: its algorithm is left to the standard library, so one seed would give different colors on each.

Template Parameters
GeneratorThe random bit generator
Parameters
[in,out]generatorThe generator to draw from; it advances by one output
Returns
The low 24 bits of the output, scaled to [0, 1).

Definition at line 51 of file Random.cppm.