Debian Codegraph @

examples/vector/interpolate.ck

raw
1 // name: interpolate.ck
2 // desc: using vec3 as a non-linear, slewing interpolator
3 // this is quite useful to making a percentage progress
4 // towards a goal, in an amount proportional to the slew
5 // and some delta time
6
7 // connect
8 SinOsc foo => dac;
9
10 // the interpolator
11 vec3 i;
12 // the interpolation rate
13 10::ms => dur irate;
14 // set initial .value, .goal, .slew
15 i.set( 440, 440, .05 * (second/irate) );
16
17 // spork interpolate function
18 spork ~ interpolate( irate );
19
20 // main shred sets the goal
21 while( true )
22 {
23 // set interpolator goal
24 i.update( Math.random2f(200,1000) );
25 // every so often
26 500::ms => now;
27 }
28
29 // function to drive interpolator(s) concurrently
30 fun void interpolate( dur delta )
31 {
32 while( true )
33 {
34 // interpolate (can also get new value via .value)
35 i.interp( delta ) => foo.freq;
36 // advance time by rate
37 delta => now;
38 }
39 }