Is there a one-line function that generates a triangle wave?

后端 未结 8 1749
暗喜
暗喜 2020-12-02 04:59

In a similar way that modulo generates a sawtooth wave. It doesn\'t have to be continuous.

here is what i mean:

int m = 10;
int x = 0;
int i         


        
8条回答
  •  长情又很酷
    2020-12-02 05:22

    Here is a periodic function that looks like a distant sine approximation; essentially it's a Sinuating paraboloid, using X squared:

    function  xs ( xx : float ): float{
    
        var xd =Mathf.Abs((Mathf.Abs(xx) % 2.4) - 1.2);
    
        if (  Mathf.Abs(Mathf.Abs(xx) % 4.8)  > 2.4){ 
            xd=(-xd*xd)+2.88;
        }else{
            xd = xd*xd;
        }
    
        return xd;
    
    }
    

提交回复
热议问题