nsk@Lerp
Linear interpolation for computing intermediate percentage values in Neural Sketch.
Overview
The \nskLerp
command computes a linear interpolation between two numeric endpoints across a specified number of elements. It is useful for dynamically varying styling parameters—such as opacity, color mixing, or dimension scaling—based on an element's position in a sequence.
Internally, \nskLerp
maps an index i
in the range [1..n] to a percentage value between from
and to
. If the to
value is between 0 and 1, it is interpreted as a fraction and scaled to 0–100.
Basic Usage
By default, the computed percentage is typeset directly. To store the result in a macro instead, use the into
key.
Example in context
In the rqt.tex
example, \nskLerp
drives a color mix across four blocks:
Here, p
will hold values 100, ~76.67, ~53.33, and 30, producing a fading color effect.
Available Options
from
(float
, default=0.0
): Starting value of the interpolation range.to
(float
, default=100.0
): Ending value of the interpolation range. Values ≤1 are treated as fractions and scaled to 0–100.n
(integer
, default=1
): Total number of interpolation steps (elements).into
(token list
, default={}
): Name of a macro to store the computed percentage. If unspecified, the value is typeset directly.
When n=1
or if the index is 1, \nskLerp
returns the from
value; for index n
, it returns the to
value.
Internal Behavior
- Scales
to
andfrom
by 100 if the providedto
value ≤1. - Computes:
- Converts the result to a decimal string for typesetting or assignment.
Reference Table
Prop | Type | Default |
---|---|---|
from? | float | 0.0 |
to? | float | 100.0 |
n? | integer | 1 |
into? | token list | {} |