diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-29 07:25:32 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 00:12:16 -0300 |
| commit | 5526c68beec454cfe607a579723b97b4848e7d3a (patch) | |
| tree | ffc111103c9b086346a2dae4148a61fe3d368780 /src/animation.zig | |
| parent | 99c088e277e7d79d7b4341d3f546c02e7254e107 (diff) | |
| download | pardes-5526c68beec454cfe607a579723b97b4848e7d3a.tar.gz pardes-5526c68beec454cfe607a579723b97b4848e7d3a.zip | |
G10: the theme's chrome fades through OKLab, easing in and out
ChromeTheme.interpolate mixes each colour in OKLab (colors.mixOklab), so a
fade between hues keeps its lightness instead of going dark and muddy mid
way; animation.Fade eases it in and out (smooth), and one retargeted mid
fade eases out from where it shows, so it never stalls. Still 10 frames
(160 ms). The page, text and syntax colours change at once as before.
Tests: OKLab round-trips its ends exactly and keeps a red-to-green mid-way
brighter than the sRGB mix. Gates as G9 (no golden moved). Feel review:
.scratch/render/crossfade/.
Diffstat (limited to 'src/animation.zig')
| -rw-r--r-- | src/animation.zig | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/animation.zig b/src/animation.zig index 855fef03..713a8a30 100644 --- a/src/animation.zig +++ b/src/animation.zig @@ -1132,6 +1132,9 @@ pub fn Fade(comptime Value: type) type { to: Value, displayed: Value, step: u16 = transition_steps, + /// Set off from partway through another fade: it eases out (moving + /// at once) instead of in and out, so it never stalls (§7.2). + retargeted: bool = false, pub fn init(value: Value) Self { return .{ .from = value, .to = value, .displayed = value }; @@ -1142,19 +1145,25 @@ pub fn Fade(comptime Value: type) type { } pub fn retarget(a: *Self, target: Value) void { + a.retargeted = a.isActive(); a.from = a.displayed; a.to = target; a.step = if (std.meta.eql(a.from, target)) transition_steps else 0; if (a.step == transition_steps) a.displayed = target; } + /// A state change eases in and out (§8.1); a retargeted one out. + const resolution: u16 = 1000; + pub fn advance(a: *Self) void { if (!a.isActive()) return; a.step += 1; + const t = @as(f32, @floatFromInt(a.step)) / @as(f32, @floatFromInt(transition_steps)); + const eased = sample(if (a.retargeted) .out_cubic else .smooth, t); a.displayed = if (a.step == transition_steps) a.to else - Value.interpolate(a.from, a.to, a.step, transition_steps); + Value.interpolate(a.from, a.to, @intFromFloat(@round(eased * resolution)), resolution); } pub fn snap(a: *Self, value: Value) void { |
