POV-Ray : Newsgroups : povray.newusers : Returning values from macros Server Time
2 May 2024 22:09:45 EDT (-0400)
  Returning values from macros (Message 5 to 14 of 24)  
<<< Previous 4 Messages Goto Latest 10 Messages Next 10 Messages >>>
From: Bald Eagle
Subject: Re: Returning values from macros
Date: 30 May 2016 14:15:00
Message: <web.574c82a476b80bcd5e7df57c0@news.povray.org>
Le_Forgeron <jgr### [at] freefr> wrote:

> Do not see macro as a function calls, but as text substitution.
>
> It might help.

Thanks Jerome - it does help - sometimes, but it still gets complicated as the
contents of the macro get larger and more complex.

I'd still like to see a few working code examples that would act as a good
reference source when trying to write and debug my own macros.

THIS you can do, THAT you can't - really helps to demonstrate it, rather than
general, generic "explanations" like in the documentation.

"Seeing" what makes or breaks a chunk code helps in having that "a-HA!" moment
that's so often needed.


Post a reply to this message

From: Cousin Ricky
Subject: Re: Returning values from macros
Date: 30 May 2016 14:50:01
Message: <web.574c8a6d76b80bcd71c9a5f20@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> I'd still like to see a few working code examples that would act as a good
> reference source when trying to write and debug my own macros.

There are two very good sources of such examples: The default include directory
and the Object Collection.


Post a reply to this message

From: Bald Eagle
Subject: Re: Returning values from macros
Date: 30 May 2016 17:15:01
Message: <web.574cac5f76b80bcd5e7df57c0@news.povray.org>
"Cousin Ricky" <rickysttATyahooDOTcom> wrote:
> "Bald Eagle" <cre### [at] netscapenet> wrote:
> > I'd still like to see a few working code examples that would act as a good
> > reference source when trying to write and debug my own macros.
>
> There are two very good sources of such examples: The default include directory
> and the Object Collection.

Right on.   I'll take a look through those and see if I can get a better grip on
the things I'd like to do.

So naughty, cleverly hiding those macros right under my nose!   :O


Post a reply to this message

From: Bald Eagle
Subject: Re: Returning values from macros
Date: 30 May 2016 17:25:00
Message: <web.574cae7f76b80bcd5e7df57c0@news.povray.org>
I've debugged a fair amount of stuff, and gotten a decent first draft of what I
was shooting for.

Has anyone used PM 2Ring's catenary macro?
I have TWO such include files - one takes 6 arguments, and the other like 11.
I couldn't get the larger one to work, and the smaller one has some issues I'm
trying to resolve.

First, the macro doesn't seem to bring the Link objects right to the endpoints,
so there's dead space - unless there's some parameter I need to tweak, or
there's a specific way to define the link object.

Second, for certain values of SLACK, and certain distances between endpoints,
the macro inverts the catenary so that it looks like anti-gravity just kicked
in.

Apparently there's a similar macro written by Mike Williams that I need to find.


I also found this rope macro, but the referenced link doesn't wind up getting
displayed properly in my browser (Chrome) - it looks like the source HTML, with
all of the tags visible, and not properly formatted as HTML.   Does anyone else
have this problem?

http://lib.povray.org/collection/rope/chrisb%201.0/rope.html


Post a reply to this message

From: jr
Subject: Re: Returning values from macros
Date: 30 May 2016 17:56:30
Message: <574cb70e$1@news.povray.org>
hi,

On 30/05/2016 22:19, Bald Eagle wrote:
> I also found this rope macro, but the referenced link doesn't wind up getting
> displayed properly in my browser (Chrome) - it looks like the source HTML, with
> all of the tags visible, and not properly formatted as HTML.   Does anyone else
> have this problem?
> 
> http://lib.povray.org/collection/rope/chrisb%201.0/rope.html

looking at that page, the <style> tag belongs inside the <head>, perhaps
that's the cause?

jr.


Post a reply to this message

From: Bald Eagle
Subject: Re: Returning values from macros
Date: 30 May 2016 18:20:01
Message: <web.574cbba576b80bcd5e7df57c0@news.povray.org>
jr <cre### [at] gmailcom> wrote:

> looking at that page, the <style> tag belongs inside the <head>, perhaps
> that's the cause?
>
> jr.

Good eye, Junior   ;)

I copied all, pasted, and cut & pasted the <head> tag above the style, and that
fixed it (locally).


Post a reply to this message

From: Cousin Ricky
Subject: Re: Returning values from macros
Date: 30 May 2016 18:35:00
Message: <web.574cbf2e76b80bcd71c9a5f20@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> I also found this rope macro, but the referenced link doesn't wind up getting
> displayed properly in my browser (Chrome) - it looks like the source HTML, with
> all of the tags visible, and not properly formatted as HTML.   Does anyone else
> have this problem?
>
> http://lib.povray.org/collection/rope/chrisb%201.0/rope.html

The <style> element is indeed in the wrong place, but that's not why you're not
getting the images.  A few years ago, the Object Collection server was
reconfigured to serve the user manuals as plain text, for security reasons.
You'll get the same result for all HTML user manuals from the Collection.

If you download the entire module, your local copy of the user manual will
render properly in your Web browser.

If you download *only* the HTML file and view it locally, your browser will
style it as HTML.  However, the images will be missing.  You can hotlink the
images by editing the HTML file using a plain text editor, and inserting

  <base href="http://lib.povray.org/collection/rope/chrisb%201.0/">

into the <head> section.  Please note that hotlinking is normally considered
extremely bad manners, but in this case, you're just loading images that would
have been served anyway.


Post a reply to this message

From: Thomas de Groot
Subject: Re: Returning values from macros
Date: 31 May 2016 03:01:12
Message: <574d36b8@news.povray.org>
On 30-5-2016 15:40, Bald Eagle wrote:
>
> I'm playing with some power transmission towers that I decided to cobble
> together.
>
> No idea why - they just suddenly captured my interest, and a recent post about
> catenary curves seemed to fuel my need to play with power lines in POV-Ray.
>

Immediately the pylon code comes to my mind. From an unknown author. See 
attached. I have used it in a couple of scenes.



-- 
Thomas


Post a reply to this message


Attachments:
Download 'danger.gif' (4 KB) Download 'danger.png' (2 KB) Download 'utf-8' (2 KB) Download 'utf-8' (20 KB)

Preview of image 'danger.gif'
danger.gif

Preview of image 'danger.png'
danger.png

From: clipka
Subject: Re: Returning values from macros
Date: 31 May 2016 12:32:34
Message: <574dbca2$1@news.povray.org>
Am 30.05.2016 um 15:40 schrieb Bald Eagle:

> Could someone please post a small, simple macro that results in a scalar, a
> vector, and an array getting passed "out" to the global SDL world?

Up to (and including) POV-Ray 3.7.0, you could use the approach
mentioned by Cousin Ricky:

    // the macro;
    // note that this macro does not actually "return" anything,
    // but has the side effect of redefining whatever variables
    // are passed as parameters
    #macro MyMacro (SomeScalar, SomeVector, SomeArray)
      // overwrite the parameters' values
      #declare SomeScalar = 4711;
      #declare SomeVector = <1,2,3>;
      #declare SomeArray = array[12];
      #local I = 0;
      #while (I < 12)
        #declare SomeArray[I] = ...;
        #local I = I + 1;
      #end
    #end

    // initialize the variables;
    // note that the types do not have to match,
    // but the variables need to be defined,
    // for rather obscure technical reasons:
    #declare MyScalar = false;
    #declare MyVector = false;
    #declare MyArray  = false;

    // call the macro, which will set the variables
    // to new values:
    MyMacro(MyScalar, MyVector, MyArray);


The current POV-Ray 3.7.1-alpha provides an alternative by making use of
a new syntax extension dubbed "tuple-style assigment":

    // the macro;
    // note that this does not take any parameters,
    // and instead "returns" the right-hand side for a
    // tuple-style assignment
    #macro MyMacro()
      #local SomeScalar = 4711;
      #local SomeVector = <1,2,3>;
      #local SomeArray = array[12];
      #local I = 0;
      #while (I < 12)
        #declare SomeArray[I] = ...;
        #local I = I + 1;
      #end
      // return all the values
      (SomeScalar, SomeVector, SomeArray)
    #end

    // invoke the macro to generate the right-hand side
    // for a tuple-style assignment;
    // note that the variables do _not_ have to be
    // defined beforehand:
    #declare (MyScalar, MyVector, MyArray) = MyMacro();

(It should be noted that this syntax extension does /not/ really add
tuple support to the SDL; all it does is provide a way to bundle
multiple assignments in such a way that the values for the entire batch
can be generated by a single macro invocation.)


Post a reply to this message

From: Bald Eagle
Subject: Re: Returning values from macros
Date: 31 May 2016 13:05:00
Message: <web.574dc43176b80bcdb488d9aa0@news.povray.org>
OK, I think I'm wrapping my head around this, finally, again.

Just curious - will there be mixed data-type support in arrays, if there are
tuple-style tricks?

Having arrays where different rows could be of different data types - scalars,
strings, vectors, whatever...   would be VERY handy.

Pipe-dream here, but:
Would you be able to have an array of faux-tuples?

I'll have to check out 3.7.1-alpha - that would help me work out what I'm
envisioning without having to struggle too much with 3.7-vanilla

Thanks as always!


Post a reply to this message

<<< Previous 4 Messages Goto Latest 10 Messages Next 10 Messages >>>

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