diff --git a/main.odin b/main.odin index 9c2526e..005db79 100644 --- a/main.odin +++ b/main.odin @@ -2,21 +2,12 @@ package main import "core:fmt" import "core:math" +import "core:math/ease" import rl "vendor:raylib" SFX: []u8 : #load("sfx.mp3") OTF: []u8 : #load("a.otf") -clampf :: proc(v: f32, lo: f32, hi: f32) -> f32 { - if v < lo do return lo - if v > hi do return hi - return v -} - -lerp :: proc(a, b, t: f32) -> f32 { - return a + (b - a) * clampf(t, 0, 1) -} - color_mul_rgb :: proc(a, b: rl.Color) -> rl.Color { return { u8((f32(a.r) * f32(b.r)) / 255), @@ -28,40 +19,27 @@ color_mul_rgb :: proc(a, b: rl.Color) -> rl.Color { with_alpha :: proc(c: rl.Color, alpha: f32) -> rl.Color { out := c - out.a = u8(clampf(alpha, 0, 1) * 255) + out.a = u8(clamp(alpha, 0, 1) * 255) return out } -// easings -ease_out_cubic :: proc(t: f32) -> f32 { - t1 := clampf(t, 0, 1) - return 1 - (1 - t1) * (1 - t1) * (1 - t1) -} -ease_in_out_cubic :: proc(t: f32) -> f32 { - t1 := clampf(t, 0, 1) - if t1 < 0.5 { - return 4 * t1 * t1 * t1 - } - u := 2 * t1 - 2 - return 0.5 * u * u * u + 1 -} ease_out_back :: proc(t: f32, s: f32 = 1.70158) -> f32 { - t1 := clampf(t, 0, 1) + t1 := clamp(t, 0, 1) return 1 + s * math.pow(t1 - 1, 3) + s * (t1 - 1) * math.pow(t1 - 1, 2) } adsr :: proc(t, attack, decay, sustain: f32, r_start: f32, r_dur: f32) -> f32 { if t <= 0 {return 0} if t < attack { - return ease_out_cubic(t / attack) + return ease.cubic_out(t / attack) } if t < attack + decay { - return lerp(1, sustain, ease_in_out_cubic((t - attack) / decay)) + return f32(math.lerp(f32(1), sustain, ease.cubic_in_out((t - attack) / decay))) } if t < r_start { return sustain } - return sustain * (1 - ease_out_cubic((t - r_start) / math.max(r_dur, 0.0001))) + return sustain * (1 - ease.cubic_out((t - r_start) / math.max(r_dur, 0.0001))) } draw_noun_verbed_sheen :: proc( @@ -165,7 +143,7 @@ draw_shadow_bar :: proc( center := center_y + offset * hf top := center - shadow_h * 0.5 - c_tint := rl.Color{tint.r, tint.g, tint.b, u8(clampf(opacity, 0, 1) * 255)} + c_tint := rl.Color{tint.r, tint.g, tint.b, u8(clamp(opacity, 0, 1) * 255)} c_clear := rl.Color{tint.r, tint.g, tint.b, 0} y0 := i32(math.round(top)) @@ -175,7 +153,7 @@ draw_shadow_bar :: proc( } y3 := y0 + total_h - fade_h := shadow_h * clampf(softness, 0, 1) * 0.5 + fade_h := shadow_h * clamp(softness, 0, 1) * 0.5 fade_i := i32(math.round(fade_h)) if fade_i * 2 > total_h { fade_i = total_h / 2 @@ -223,7 +201,7 @@ draw_sheen_sweep :: proc( width := size.x height := size.y - p := clampf(progress, 0, 1) + p := clamp(progress, 0, 1) x_center := left + width * p core_w := width * core_frac @@ -363,13 +341,13 @@ main :: proc() { post_hold := post_hold_after_sweep * DUR_SCALE post_out := post_fade_out_dur * DUR_SCALE - alpha := ease_out_cubic(t / fade_in) + alpha := ease.cubic_out(t / fade_in) scale_bump := 0.06 * ease_out_back(t / scale_len, 1.3) base_font_size0 := 0.6 * 0.25 * f32(rl.GetScreenHeight()) font_size := base_font_size0 * (1.0 + scale_bump) - glow_in := ease_out_cubic(t / glow_len) + glow_in := ease.cubic_out(t / glow_len) glow_pulse := 0.5 + 0.5 * f32(math.sin(t * 2.0)) sweep_end_time := sweep_dly + sweep_len @@ -383,10 +361,10 @@ main :: proc() { fade_out_start, // release start post_out, // release dur ) - blur_size := blur_base * lerp(1.00, 1.30, ease_in_out_cubic(blur_env)) + blur_size := blur_base * f32(math.lerp(f32(1.00), 1.30, ease.cubic_in_out(blur_env))) blur_opacity := blur_opacity_base blur_opacity *= (0.60 + 0.40 * blur_env) // grow with env - blur_opacity *= clampf(glow_in * (0.8 + 0.2 * glow_pulse), 0.0, 1.0) + blur_opacity *= clamp(glow_in * (0.8 + 0.2 * glow_pulse), 0.0, 1.0) sheen_t := t - sweep_dly @@ -398,13 +376,17 @@ main :: proc() { sweep_len, 0.28 * DUR_SCALE, ) - sheen_env := math.pow(clampf(raw_env, 0, 1), 0.75) * SHEEN_GAIN + sheen_env := f32(math.pow(clamp(raw_env, 0, 1), 0.75) * SHEEN_GAIN) - core_frac := lerp(0.12, 0.18, sheen_env) * SHEEN_W_SCALE - soft_frac := lerp(0.24, 0.34, sheen_env) * SHEEN_W_SCALE + core_frac := f32(math.lerp(f32(0.12), 0.18, sheen_env) * SHEEN_W_SCALE) + soft_frac := f32(math.lerp(f32(0.24), 0.34, sheen_env) * SHEEN_W_SCALE) - core_alpha_dyn := math.min(lerp(0.10, 0.26, sheen_env), SHEEN_CORE_ALPHA_CAP) - soft_alpha_dyn := math.min(lerp(0.03, 0.09, sheen_env), SHEEN_SOFT_ALPHA_CAP) + core_alpha_dyn := f32( + math.min(math.lerp(f32(0.10), 0.26, sheen_env), SHEEN_CORE_ALPHA_CAP), + ) + soft_alpha_dyn := f32( + math.min(math.lerp(f32(0.03), 0.09, sheen_env), SHEEN_SOFT_ALPHA_CAP), + ) center := rl.Vector2{f32(rl.GetScreenWidth()) * 0.5, f32(rl.GetScreenHeight()) * 0.5} @@ -427,7 +409,7 @@ main :: proc() { blur_opacity, ) - sweep_p := clampf((t - sweep_dly) / sweep_len, 0, 1) + sweep_p := clamp((t - sweep_dly) / sweep_len, 0, 1) if sweep_p > 0 && sweep_p <= 1 { draw_sheen_sweep( font, @@ -452,11 +434,11 @@ main :: proc() { post_alpha = 0 } else { if t < post_in { - post_alpha = ease_out_cubic(t / post_in) + post_alpha = ease.cubic_out(t / post_in) } else if t >= fade_out_start { - post_alpha = 1.0 - ease_out_cubic((t - fade_out_start) / post_out) + post_alpha = 1.0 - ease.cubic_out((t - fade_out_start) / post_out) } - post_alpha = clampf(post_alpha, 0, 1) + post_alpha = clamp(post_alpha, 0, 1) } rl.BeginDrawing()