38 lines
1.2 KiB
Plaintext
38 lines
1.2 KiB
Plaintext
|
( timer + lerping )
|
||
|
: clamp0 ( range val -- i )
|
||
|
2dup <= if drop else
|
||
|
dup 0 <= if drop drop 0 else
|
||
|
swap drop then then ;
|
||
|
: >ratio ( range value -- f )
|
||
|
over swap clamp0 swap />ratio ;
|
||
|
: <ratio ( range ratio -- v ) *<ratio ;
|
||
|
: >range ( start end -- start range ) over - ;
|
||
|
: <range ( start range -- start end ) over + ;
|
||
|
: lerpr ( start end ratio ) r> >range r< <ratio + ;
|
||
|
: lerpn ( start1 end1 start2 end2 val )
|
||
|
r> >range r< <rot - >ratio lerpr ;
|
||
|
: lerp ( start end duration start -- i )
|
||
|
ticks udelta ( start end duration delta )
|
||
|
>ratio lerpr ;
|
||
|
|
||
|
: triggered ( duration timer -- b )
|
||
|
dup r> @ ticks udelta ( duration delta )
|
||
|
2dup <= if drop r< +! 1 else drop drop rdrop 0 then ;
|
||
|
|
||
|
: now! ( timer -- ) ticks swap ! ;
|
||
|
: advance! ( timer -- delta )
|
||
|
dup @ ticks udelta ( timer delta )
|
||
|
dup <rot +! ;
|
||
|
|
||
|
: move-to ( target speed p -- )
|
||
|
dup r> @ >rot ticks ( from to duration start )
|
||
|
begin
|
||
|
4dup lerp r@ !
|
||
|
<rot dup r@ @ != ( from duration start to !done )
|
||
|
while
|
||
|
>rot suspend
|
||
|
repeat rdrop drop drop drop drop ;
|
||
|
|
||
|
: sleep ( count -- )
|
||
|
ticks swap begin over ticks udelta over u< while suspend repeat drop drop ;
|