Skip to content

lerp.um

Marek Maskarinec edited this page Oct 9, 2022 · 2 revisions

lerp.um

 Simple linear interpolation module.

struct Any*

type Any* = interface{}

struct Item*

type Item* = struct {
	start, end: th.fu
	length: th.uu
	progress: th.fu
	swap: bool
	ctx: Any
	callback: fn(ctx: Any)
}

Lerper queue item. It interpolates between start and end for the duration of length in ms. Additionally you can enable swap, which instead of dequeueing swaps start and end and resets the progress.

fn mk*

fn mk*(start, end: th.fu, length: th.uu, swap: bool = false): Item {

Item's constructor

struct Lerper*

type Lerper* = []Item

Lerper is a queue of items. It will lerp the first one and if it ends and doesn't have swap enabled, it will dequeue it.

fn dequeue*

fn (l: ^Lerper) dequeue*() {

Removes the first lerper item.

fn enqueue*

fn (l: ^Lerper) enqueue*(i: Item) {

Adds an item to l's queue

fn byDelta*

fn (l: ^Lerper) byDelta*(delta: th.uu): th.fu {

Interpolates the front by delta. And returns it's value.

Clone this wiki locally