Creating a list of sinusoidal values over varying intervals

Soen Eber

Vatican mole
VVO Supporter 🍦🎈👾❤
Joined
Sep 20, 2018
Messages
4,011
This script generates a list of sinusoidal values between 0.0 .. 1.0 (ascending) or 1.0 .. 0.0 (descending)
Use Case: can be used to emulate acceleration and deceleration without resorting to vehicle or physics scripting. I.E., a way to "fake it" convincingly, or to emulate the up & down motion of a wheel and devices derived from wheeled power, such as a pump. For my own use case, I am emulating a humorous version of having the hiccups, with a lot of activity during the first couple minutes before decaying to a slower and less noticeable continuation, on the principle that "a funny gag is only good for the first two minutes."

Code:
// sine list
list _l_sine = [];
integer _n;
    
// build list of sine values between 0.0 and 1.0, inclusively
// steps: integer whole number, number of values generated
// reverse: TRUE = reversed (descending)
//        : FALSE = not reversed (ascending)
//
list sine_progression(integer steps, integer reverse)
{
    list l;
    float f;
    float i;
    integer start = 0;
    if (reverse) start = 90;
    integer end = start + 90;

    float step = 90/(float)(steps-1);
    for (i=0; i<= 90; i+= step) {
        f = llSin((i+start)*DEG_TO_RAD);
        l += [f];
    }
    return l;
}
init()
{
    // sine list
    _n=20;
    _l_sine = sine_progression(_n, FALSE);
}
// sine list: this code is optional, specific to testing
walk_sines()
{
    llOwnerSay((string)_n+" steps");
    integer i;
    float f;
    for (i=0; i<llGetListLength(_l_sine); i++) {
        llOwnerSay(
          (string)(i+1)+" "+(string)llList2Float(_l_sine, i)
        );
    }
}
default
{
    state_entry()
    {
        init();
    }
    touch_start(integer total_number)
    {
        walk_sines();
    }
}
This generates a list such as:
Code:
3:27] sine project 1.1: 20 steps
[13:27] sine project 1.1: 1 0.000000
[13:27] sine project 1.1: 2 0.082579
[13:27] sine project 1.1: 3 0.164595
[13:27] sine project 1.1: 4 0.245485
[13:27] sine project 1.1: 5 0.324699
[13:27] sine project 1.1: 6 0.401695
[13:27] sine project 1.1: 7 0.475947
[13:27] sine project 1.1: 8 0.546948
[13:27] sine project 1.1: 9 0.614213
[13:27] sine project 1.1: 10 0.677282
[13:27] sine project 1.1: 11 0.735724
[13:27] sine project 1.1: 12 0.789141
[13:27] sine project 1.1: 13 0.837167
[13:27] sine project 1.1: 14 0.879474
[13:27] sine project 1.1: 15 0.915773
[13:27] sine project 1.1: 16 0.945817
[13:27] sine project 1.1: 17 0.969400
[13:27] sine project 1.1: 18 0.986361
[13:27] sine project 1.1: 19 0.996584
[13:27] sine project 1.1: 20 1.000000
The actual list is restrained to the sine values.only
 
Last edited:
  • 1Like
Reactions: Khamon

Free

It's all in my head.
VVO Supporter 🍦🎈👾❤
Joined
Sep 22, 2018
Messages
43,201
Location
Moonbase Caligula
SL Rez
2008
Joined SLU
2009
SLU Posts
55565
What do you call a manic-depressive mathematician with a nasal clog? Sinusoidal.