# ui_ease.ludic — easing never depends on the frame rate: a transition and an animation stepped at # 60, 120, 180 and 240 Hz on the program's clock are at the same value half way (kept in float, never # cut to whole pixels) and land exactly on their targets when their time is up. import "ludic.ui" program UiEase { numbers float state UiEaseState { dim: bool = false now: float = 0.0 } view Ease (ui_ease_st: UiEaseState) { dim = ui_ease_st.dim } const STYLE: string = "" const BODY: string = "
a
b
c
" function clock(ui_ease_st: UiEaseState) -> float { return ui_ease_st.now } function nodes(ui_st: mut UiState, name: string) -> UiNode { ui_show(ui_st, name, view_ease(), 0.0, 0.0, 200.0, 200.0) return ui_nodes(ui_st, name, view_ease()) } # one rate, on its own screen: the slide from its first frame, the fade from half a second in function at_rate(ui_ease_st: mut UiEaseState, ui_st: mut UiState, hz: int) -> string { let name = `r{hz}` ui_ease_st.dim = false var mid = "" var slid = false var landed = false var over = false for k in 0 .. hz + 1 { ui_ease_st.now = float(k) / float(hz) if k == hz / 2 { ui_ease_st.dim = true } let r = nodes(ui_st, name) let go = r.children[0] let soft = r.children[1] let want = r.children[2].alpha if k == hz / 10 { mid = `{int(Math.round(go.left * 100.0))} ` } if k == hz / 2 + hz / 10 { mid = mid + `{int(Math.round(soft.alpha * 1000.0))}` } if k == hz / 4 { slid = go.left == 37.0 } if k == hz / 2 + hz / 4 { landed = soft.alpha == want } if k > hz / 2 + hz / 4 and soft.alpha != want { over = true } } return `{hz}: {mid} slid {slid} landed {landed} left {over}` } entry (ui_ease_st: mut UiEaseState, ui_st: mut UiState) { ui_backend(ui_st, new UiBackend) ui_clock(ui_st, fn clock) var page = "