POV-Ray : Newsgroups : povray.newusers : functions and macros : Re: functions and macros Server Time
18 May 2024 03:45:59 EDT (-0400)
  Re: functions and macros  
From: Bald Eagle
Date: 25 Jun 2023 07:30:00
Message: <web.649824c41d2497941f9dae3025979125@news.povray.org>
kurtz le pirate <kur### [at] gmailcom> wrote:

> indeed, converting the macro into functions is the best solution ... but
> functions also have limitations.

They do, but you can still do a surprising amount with them.

I've converted your macro to a set of two daisy-chained functions to show you
how that would work.

However, you only need a single stock function, instead of an
algorithmic/programmatic approach.  mod (N, 1) returns the fractional part of
any value, which is what you're looking for.



#macro limit_zero2one(_value)
 #local limited = _value - floor(_value);
 #if (limited < 0)
  #local limited = limited + 1.0;
 #end

 limited

#end

#declare precalc = function (_value) {_value - floor(_value)}

#declare Limit_zero2one = function (_value) {select (precalc (_value), precalc
(_value) + 1, precalc (_value), precalc (_value) )}


#local Seed = seed (123);
#for (N, 0, 10)
 #local N2 = rand (Seed) * N + rand (Seed);

 #debug concat( " Initial value = ", str(N2, 0, 3),  " Function result = ",
str(Limit_zero2one (N2), 0, 3), "\n")

#end

#debug "\n"


#for (N, 0, 10)
 #local N2 = rand (Seed) * N + rand (Seed);

 #debug concat( " Initial value = ", str(N2, 0, 3),  " Function result = ",
str(mod (N2, 1), 0, 3), "\n")

#end

#debug "\n"


#error "No objects in scene."


- BW


Post a reply to this message


Attachments:
Download 'kurtz_functions.pov.txt' (1 KB)

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