2019-03-09 23:49:45 +00:00
|
|
|
( 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 + ;
|
2019-05-17 01:05:40 +00:00
|
|
|
: lerpr ( start end ratio ) >r >range <r <ratio + ;
|
2019-03-09 23:49:45 +00:00
|
|
|
: lerpn ( start1 end1 start2 end2 val )
|
2019-05-17 01:05:40 +00:00
|
|
|
>r >range <r <rot - >ratio lerpr ;
|
2019-03-09 23:49:45 +00:00
|
|
|
: lerp ( start end duration start -- i )
|
|
|
|
ticks udelta ( start end duration delta )
|
|
|
|
>ratio lerpr ;
|
|
|
|
|
|
|
|
: triggered ( duration timer -- b )
|
2019-05-17 01:05:40 +00:00
|
|
|
dup >r @ ticks udelta ( duration delta )
|
|
|
|
2dup <= if drop <r +! 1 else drop drop rdrop 0 then ;
|
2019-03-09 23:49:45 +00:00
|
|
|
|
|
|
|
: now! ( timer -- ) ticks swap ! ;
|
|
|
|
: advance! ( timer -- delta )
|
|
|
|
dup @ ticks udelta ( timer delta )
|
|
|
|
dup <rot +! ;
|
|
|
|
|
|
|
|
: move-to ( target speed p -- )
|
2019-05-17 01:05:40 +00:00
|
|
|
dup >r @ >rot ticks ( from to duration start )
|
2019-03-09 23:49:45 +00:00
|
|
|
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 ;
|