POV-Ray : Newsgroups : povray.general : declare a variable in a function : Re: declare a variable in a function Server Time
16 Jun 2021 09:40:54 EDT (-0400)
  Re: declare a variable in a function  
From: ingo
Date: 2 Apr 2021 17:13:22
Message: <XnsAD00EC3ADF180seed7@news.povray.org>
in news:606753c7$1@news.povray.org William F Pokorny wrote:

> I'm not aware of any such feature

Bill, Tor Olav,

Usefull suggestions, as allways. Thanks! But I'm just not sure either one 
of the ways is what I'm thinkin' of. I.i.r.c It was something Thorsten 
mentioned / showed when functions where introduced. 
Anyway I'll study your suggestions. For now I "fixed" it by calling 
another function. Works fine, no hurries.

/*:Ramp Oscilator, goes from 0 to 1 over 1 Frequency period

Not for direct sound use because of DC.
*/
#declare Ramp = function(Freq, Amp, Tick, SRate){
  Amp * mod(Tick, 1/(Freq/SRate)) * (Freq/SRate)
}


/*:Triangle wave Oscilator*/
#declare TriangleOsc = function(Freq, Amp, Tick, SRate){
  (select (
    Ramp(Freq, 1, Tick, SRate) - 0.25,
    Ramp(Freq, 1, Tick, SRate) * 4,
    select(
      Ramp(Freq, 1, Tick, SRate) - 0.75,
      2 - Ramp(Freq, 1, Tick, SRate) * 4,
      Ramp(Freq, 1, Tick, SRate) * 4 - 4
    )
  )) * Amp
}


Cheers,

Ingo


Post a reply to this message

Copyright 2003-2021 Persistence of Vision Raytracer Pty. Ltd.