Skip to content

textmode.js / TextmodeGlyphRamp

Class: TextmodeGlyphRamp ​

Immutable character sequence for mapping numbers to glyphs.

TextmodeGlyphRamp stores a low-to-high sequence of grapheme clusters and maps normalized values to one glyph from that sequence.

Use Textmodifier.createGlyphRamp to create ramps inside a sketch.

Example ​

Constructors ​

Constructor ​

ts
new TextmodeGlyphRamp(characters): TextmodeGlyphRamp;

Create a ramp from characters ordered from low values to high values.

At least two grapheme clusters are required.

Parameters ​

ParameterTypeDescription
charactersstringCharacter sequence ordered from low to high.

Returns ​

TextmodeGlyphRamp

Example ​

Properties ​

characters ​

ts
readonly characters: string;

The character sequence this ramp was created with.


length ​

ts
readonly length: number;

Number of grapheme clusters in the ramp.

Methods ​

at() ​

Call Signature ​

ts
at(normalizedValue): string;

Map a normalized value to a character.

Values outside [0, 1] are clamped. 0 returns the first character, and 1 returns the last character.

Parameters ​
ParameterTypeDescription
normalizedValuenumberNormalized value to map.
Returns ​

string

Character from this ramp.

Example ​

Call Signature ​

ts
at(
   value, 
   min, 
   max): string;

Map a value from a source range to a character.

The value is normalized using min and max, then mapped through this ramp. Reversed ranges are supported. Equal range bounds are invalid.

Parameters ​
ParameterTypeDescription
valuenumberValue to map.
minnumberSource range minimum.
maxnumberSource range maximum.
Returns ​

string

Character from this ramp.

Example ​

shift() ​

ts
shift(amount): TextmodeGlyphRamp;

Return a shifted copy of this ramp.

Positive amounts rotate forward and negative amounts rotate backward. Fractional amounts are truncated before rotation.

Parameters ​

ParameterTypeDescription
amountnumberNumber of character steps to shift.

Returns ​

TextmodeGlyphRamp

A new shifted ramp.

Example ​