POV-Ray : Newsgroups : povray.general : declare a variable in a function : Re: declare a variable in a function Server Time
18 Apr 2024 11:21:11 EDT (-0400)
  Re: declare a variable in a function  
From: Tor Olav Kristensen
Date: 2 Apr 2021 19:05:00
Message: <web.6067a28edb16780d6f19eb189db30a9@news.povray.org>
ingo <ing### [at] tagpovrayorg> wrote:
> 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.
> */
>...

Ingo

I'm sorry, but I have no recollection of such a feature.

In your TriangleOsc function the same Ramp value is calculated 5 times.
If you want more efficient functions then I suggest something like this:

#declare TempFn =
    function(Ramp) {
        select(
            Ramp - 0.25,
            Ramp,
            select(
                Ramp - 0.75,
                0.5 - Ramp,
                Ramp - 1
            )
        )
    }
;

#declare TriangleOscFn =
    function(Freq, Amp, Tick, SRate) {
        4*Amp*TempFn(Freq/SRate*mod(Tick, SRate/Freq))
    }
;

--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message

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