ludic/math-lerp.html
2026-09-17 22:10:03 +00:00

35 lines
No EOL
2.6 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Math.lerp — Ludic</title>
<meta name="description" content="Blend between two values by a 0..1 amount.">
<link rel="stylesheet" href="base.css">
<link rel="stylesheet" href="docs.css">
</head>
<body>
<header class="nav"><div class="wrap nav-in"><a class="brand" href="index.html"><span class="logo">L</span> Ludic</a><button class="nav-toggle" aria-label="Toggle menu" aria-expanded="false">☰</button><nav class="nav-links"><a href="index.html">Home</a><a href="api.html">API Reference</a><a class="nav-cta" href="https://git.workshopsoft.io/workshopsoft/ludic">Source ↗</a></nav></div></header>
<main class="wrap item">
<div class="crumbs"><a href="api.html">API Reference</a> <span>›</span> <a href="ns-math.html">Math</a> <span>›</span> <span class="here">Math.lerp</span></div>
<div class="item-head">
<span class="kind-badge kind-method">method</span>
<h1 id="top">Math.lerp</h1>
</div>
<code class="sig">Math.lerp(a, b, t) -&gt; fixed</code>
<div class="desc"><p>Linear interpolation: returns <code>a</code> when <code>t</code> is <code>0.0</code>, <code>b</code> when <code>t</code> is <code>1.0</code>, and a proportional blend in between — the exact value <code>a + (b - a) * t</code>. All three arguments are <code>fixed</code> and the result is <code>fixed</code>. It is the workhorse behind smooth motion: ease a camera toward a target, fade a value over time, or sample a gradient. Values of <code>t</code> outside <code>0..1</code> extrapolate past the endpoints.</p></div>
<div class="params"><h2>Parameters</h2><div class="param" id="param-a"><code class="pname">a</code><span class="pdesc">the value returned at <code>t = 0.0</code></span></div><div class="param" id="param-b"><code class="pname">b</code><span class="pdesc">the value returned at <code>t = 1.0</code></span></div><div class="param" id="param-t"><code class="pname">t</code><span class="pdesc">the blend amount, normally <code>0.0</code>..<code>1.0</code></span></div></div>
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program EaseCamera {
var camera_x: fixed = 0.0
var target_x: fixed = 100.0
handler Follow phase Update {
camera_x = Math.lerp(camera_x, target_x, 0.1) # glides a tenth of the way each frame
}
}</pre></div>
<a class="back" href="api.html">← All symbols</a>
</main>
<script src="ludic-highlight.js"></script>
<script>Ludic.highlightAll(); Ludic.installCards(); Ludic.flashTarget();</script>
</body></html>