POV-Ray : Newsgroups : povray.advanced-users : Can strings be used to create identifiers? : Re: Can strings be used to create identifiers? Server Time
25 Jun 2024 23:43:55 EDT (-0400)
  Re: Can strings be used to create identifiers?  
From: Kenneth
Date: 25 Feb 2014 04:35:01
Message: <web.530c62c2e7c7ab47c2d977c20@news.povray.org>
Thomas de Groot <tho### [at] degrootorg> wrote:

>
> Just out of curiosity, what would the advantage be of this trick? I
> assume that calling such a macro would increase parsing time, even if by
> only a tiny, tiny bit ;-)
>

When I was designing my 'animation blurring' scheme several years ago (i.e.,
averaging 10 or more frames to create motion blur), I was trying to come up with
a way to easily tell my code what type of image files I was going to use (.bmp,
..png, .jpeg), without having to do that in the body of the code (in the pigment
statement itself) but rather at the beginning of the scene. That's where I like
to add all of my 'switches,' to set up parameters, turn things on and off, etc.
So I worked out a scheme that uses strings for *part* of what I wanted to do,
but not all. Here's an example code snippet, buried way down in my code:

image_map{jpeg "my_image" once} // inside a #while loop, using a pigment_map
// to average lots of images together to get blur

For the 'my_image' part, I built a string construction that automatically takes
the 'real' image name (along with its included number in the animation
sequence), adds a period, then adds 'jpeg' after it, then it is all #declared as
my_image. (Same for the other file types, using a rather ugly #switch
statement.) So it's mostly automatic; all I have to do at the beginning of the
file is to specify what the real file name is, and the file type-- both as
#declared strings.

But I didn't know how to likewise create the 'file type' that comes immediately
after image_map{   as it's a KEYWORD. I've basically been looking for a more
'elegant' way of doing that. ;-) So now, with Alain's #macro idea, I can
automate that small bit of the process as well!

In a bigger context, it seems to me that this particular kind of macro use might
be a way to #declare things that are not normally declare-able. Keywords might
be just *one* example-- although I can't think of any others right now.


Post a reply to this message

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