|
55 | 55 | <li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-round">round</a></span></span></li> |
56 | 56 | <li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-scalar">scalar</a></span></span></li> |
57 | 57 | <li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-scale">scale</a></span></span></li> |
| 58 | +<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-seq">seq</a></span></span></li> |
58 | 59 | <li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-smoothstep">smoothstep</a></span></span></li> |
59 | 60 | <li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-step">step</a></span></span></li> |
60 | 61 | <li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-stepArray">stepArray</a></span></span></li> |
|
568 | 569 | return target; |
569 | 570 | } |
570 | 571 |
|
| 572 | +/** |
| 573 | + * Generates a list of interpolated values between from and to, |
| 574 | + * where the number of elements returned are controlled by the |
| 575 | + * steps argument. |
| 576 | + * @param {number/Array} from value to interpolate from |
| 577 | + * @param {number/Array} to value to interpolate to |
| 578 | + * @param {number} steps interpolation steps |
| 579 | + * @param {number} start start time of interpolation [0-1] |
| 580 | + * @param {number} end end time of interpolation [0-1] |
| 581 | + */ |
| 582 | +export function seq(from, to, steps, start = 0, end = 1) { |
| 583 | + let f; |
| 584 | + if (Array.isArray(from)) { |
| 585 | + f = t => mix(from, to, t, from.slice()); |
| 586 | + } else { |
| 587 | + f = t => lerp(from, to, t); |
| 588 | + } |
| 589 | + const target = []; |
| 590 | + const incr = (end - start) / (steps - 1); |
| 591 | + for (let i = 0; i < steps - 1; i++) { |
| 592 | + const x = start + i * incr; |
| 593 | + target.push(f(x)); |
| 594 | + } |
| 595 | + target.push(f(end)); |
| 596 | + return target; |
| 597 | +} |
| 598 | + |
571 | 599 | /** |
572 | 600 | * Rounds a number to the specific number of digits. Works with either a |
573 | 601 | * single number or an array of numbers, which means it can be used with vectors and |
|
576 | 604 | * @param {number} digits number of digits to round to |
577 | 605 | * @return {number} rounded value |
578 | 606 | */ |
579 | | -export function round(v, digits) { |
| 607 | +export function round(v, digits = 1) { |
580 | 608 | const f = 10 ** digits; |
581 | 609 | if (!Array.isArray(v)) { |
582 | 610 | return Math.round(v * f) / f; |
|
614 | 642 | const v = r % TAU; |
615 | 643 | return (v < 0 ? v + TAU : v); |
616 | 644 | } |
617 | | - |
618 | 645 | </code></pre> |
619 | 646 |
|
620 | 647 | </div> |
|
0 commit comments