|
|
clipka <ano### [at] anonymousorg> wrote:
> Am 19.09.2018 um 17:58 schrieb Bald Eagle:
> > Along the same lines, is it possible to assign an image_map file type
> > to a variable-- like png, jpeg, etc. ?
>
> ...reasonably clean would be the following construct:
>
> #macro FormatKeyword(Format)
> #if (Format = "png")
> png
> #elif (Format = "jpeg")
> jpeg
> ....
> #end
> #end
>
> #declare Format = "png";
> image_map { FormatKeyword(Format) "foo.png" }
Hey, that's GREAT! I struggled with this idea years ago, and had to use some
ugly kludges to get this result. Using a macro didn't occur to me (I probably
thought it wouldn't work.) Thanks, it's a really nice construct.
This would be the (longer) way that I would write such a macro (just for
visual/mental clarity):
#macro FormatKeyword(Format)
#if (Format = "png")
png
#else
#if(Format = "jpeg")
jpeg
#else
#if(Format = "bmp")
bmp
#else
#end
#end
#end
#end // of macro
#declare Format = "png";
box{0,1
pigment{
image_map{FormatKeyword(Format) "crater demo as PNG.png" interpolate 2}
.... which works very nicely.
A couple of questions/observations, though: The docs say two things at
"3.3.2.6.1 The if...else...end Directives" (in v3.7.1 beta 9's help file--
although I haven't yet checked the online wiki):
"...an optional #elseif clause is now supported."
and
"NOTE: Nesting directives in the following manner has been known to cause
problems during the parse phase.
#if( #if(yes) yes #end ) #end
"
The even shorter keyword #elif (for #elseif) is not mentioned there (even
though it works); and, its keyword 'color' in scsne code looks like a
'non'-keyword. Should both of those little errors be fixed?
More importantly, I've never had a problem using nested #if's (when including
all of the #else keywords, anyway.) I *think* my macro is a good demonstration
of what the docs mean by nested #ifs as explained there(?) So are the new
keywords #elseif and #elif designed to eliminate any *possible* nested-#ifs
problems (along with being 'shorthand' versions of such constructs)? Just
curious.
Post a reply to this message
|
|