灵符lingfu

lingdev

↓ 0 downloads

LingDev: a Godot / Unity-style game editor written in Ling. 2-D and 3-D scenes, Flash-style timeline and cutscenes, HUDs over 3-D, Ling scripting, audio / music / MIDI, builds for Windows, Linux, macOS, web, Raspberry Pi and LingOS. Ships with Ling Agent (an N64-style spy FPS), Ling Breaker (a 3-D breakout) and Moko's Picture Book (a kawaii storybook platformer).

Windows · x86-64Linux · x86-64LingOS · x86-64LingOS · Pi 5 ARM64Web · WASM
Keywords game-engine, editor, 3d, 2d, cutscene, timeline, ling, lingos, raspberry-pi
lingfu install lingdev
LicenseApache-2.0 OR MIT
Authorsling-lin
READMECode / FilesVersionsDependency GraphDependentsSecurityBuildsSettings

Code / Files (136)

ling/rt/rt_ease.ling
# rt_ease.ling - easing curves, in Ling so they run on every runtime (desktop, web, LingOS kernel).
# Names match the engine's tween_ease kinds.

fn ease_names() {
    return ["linear", "step", "quad_in", "quad_out", "quad_in_out", "cubic_in", "cubic_out", "cubic_in_out", "sine_in", "sine_out", "sine_in_out", "expo_in", "expo_out", "expo_in_out", "back_in", "back_out", "back_in_out", "elastic_in", "elastic_out", "bounce_in", "bounce_out"]
}

fn ease_bounce_out(t) {
    if t < 1.0 / 2.75 { return 7.5625 * t * t }
    if t < 2.0 / 2.75 {
        bind u = t - 1.5 / 2.75
        return 7.5625 * u * u + 0.75
    }
    if t < 2.5 / 2.75 {
        bind u = t - 2.25 / 2.75
        return 7.5625 * u * u + 0.9375
    }
    bind u = t - 2.625 / 2.75
    return 7.5625 * u * u + 0.984375
}

fn ease(kind, t) {
    bind t = clampf(t, 0.0, 1.0)
    if kind == "linear" || kind == "" { return t }
    if kind == "step" { return sel(t >= 1.0, 1.0, 0.0) }
    if kind == "quad_in" { return t * t }
    if kind == "quad_out" { return 1.0 - (1.0 - t) * (1.0 - t) }
    if kind == "quad_in_out" {
        if t < 0.5 { return 2.0 * t * t }
        return 1.0 - pow(0.0 - 2.0 * t + 2.0, 2.0) / 2.0
    }
    if kind == "cubic_in" { return t * t * t }
    if kind == "cubic_out" { return 1.0 - pow(1.0 - t, 3.0) }
    if kind == "cubic_in_out" || kind == "smooth" {
        if t < 0.5 { return 4.0 * t * t * t }
        return 1.0 - pow(0.0 - 2.0 * t + 2.0, 3.0) / 2.0
    }
    if kind == "sine_in" { return 1.0 - cos(t * 1.5707963) }
    if kind == "sine_out" { return sin(t * 1.5707963) }
    if kind == "sine_in_out" { return 0.0 - (cos(3.14159265 * t) - 1.0) / 2.0 }
    if kind == "expo_in" {
        if t <= 0.0 { return 0.0 }
        return pow(2.0, 10.0 * t - 10.0)
    }
    if kind == "expo_out" {
        if t >= 1.0 { return 1.0 }
        return 1.0 - pow(2.0, 0.0 - 10.0 * t)
    }
    if kind == "expo_in_out" {
        if t <= 0.0 { return 0.0 }
        if t >= 1.0 { return 1.0 }
        if t < 0.5 { return pow(2.0, 20.0 * t - 10.0) / 2.0 }
        return (2.0 - pow(2.0, 0.0 - 20.0 * t + 10.0)) / 2.0
    }
    if kind == "back_in" {
        bind c1 = 1.70158
        return (c1 + 1.0) * t * t * t - c1 * t * t
    }
    if kind == "back_out" || kind == "overshoot" {
        bind c1 = 1.70158
        bind u = t - 1.0
        return 1.0 + (c1 + 1.0) * u * u * u + c1 * u * u
    }
    if kind == "back_in_out" {
        bind c2 = 1.70158 * 1.525
        if t < 0.5 { return (pow(2.0 * t, 2.0) * ((c2 + 1.0) * 2.0 * t - c2)) / 2.0 }
        return (pow(2.0 * t - 2.0, 2.0) * ((c2 + 1.0) * (t * 2.0 - 2.0) + c2) + 2.0) / 2.0
    }
    if kind == "elastic_in" {
        if t <= 0.0 { return 0.0 }
        if t >= 1.0 { return 1.0 }
        return 0.0 - pow(2.0, 10.0 * t - 10.0) * sin((t * 10.0 - 10.75) * 2.0943951)
    }
    if kind == "elastic_out" || kind == "elastic" {
        if t <= 0.0 { return 0.0 }
        if t >= 1.0 { return 1.0 }
        return pow(2.0, 0.0 - 10.0 * t) * sin((t * 10.0 - 0.75) * 2.0943951) + 1.0
    }
    if kind == "bounce_out" || kind == "bounce" { return ease_bounce_out(t) }
    if kind == "bounce_in" { return 1.0 - ease_bounce_out(1.0 - t) }
    return t
}

fn ease_lerp(a, b, t, kind) { return a + (b - a) * ease(kind, t) }

# angle interpolation on the short way round (radians)
fn ease_angle(a, b, t, kind) {
    bind d = b - a
    while d > 3.14159265 { bind d = d - 6.2831853 }
    while d < 0.0 - 3.14159265 { bind d = d + 6.2831853 }
    return a + d * ease(kind, t)
}

← Back to index