POV-Ray : Newsgroups : povray.windows : Problem with macros and translate function :/ Server Time
28 Apr 2024 05:15:03 EDT (-0400)
  Problem with macros and translate function :/ (Message 1 to 2 of 2)  
From: aysays
Subject: Problem with macros and translate function :/
Date: 23 Aug 2023 08:00:00
Message: <web.64e5f4acd9dedc30941194678c4c5f32@news.povray.org>
Hello I'm new to Pov-Ray and am trying to write a broccoli fractal code however
I'm having problems with the translate function. If I understood it correctly,
translate only accepts numerical values. I tried writing a macro but that didn't
work either. How am I supposed to write a recursive function that utilizes
translate? :/ Here is my code:

#include "colors.inc"

global_settings {
    ambient_light rgb <1, 1, 1>
    assumed_gamma 1.0
}

camera {
    location <0, 0, -25>
    look_at <0, 0, 0>
}

light_source {
    <-100, -100, -100>
    color rgb <1, 1, 1>
}

#declare phi = (1 + sqrt(5))/2;
#declare ang = 360 * (1 - 1/phi);




#macro trans()
    translate< sqrt(i)* cos(i * ang),
           sqrt(i) * sin(i * ang),
           10-sqrt(pow(sqrt(i)* cos(i * ang),2) + pow(sqrt(i) * sin(i *
ang),2))>
#end

#macro frac(n)
    #if(n > 0)
        cone {
            <0, 10, 0>, 10
            <0, 0, 0>, 0
            texture {
                pigment { Green }
                finish { ambient 0.2 }
            }


        #declare i = 1;
        #while (i <= 100)
            //#declare theta = i * ang;
            //#declare r = sqrt(i);
            //#declare a = r * cos(theta);
            //#declare b = r * sin(theta);


            trans()



            scale 0.15
       }
            frac(n - 1)

            #declare i = i + 1;
        #end
    #end
#end

frac(3);



Thanks in advance :)


Post a reply to this message

From: Leroy
Subject: Re: Problem with macros and translate function :/
Date: 23 Aug 2023 14:25:00
Message: <web.64e64e5cd6a8965bd082ffedf712fc00@news.povray.org>
"aysays" <nomail@nomail> wrote:
> Hello I'm new to Pov-Ray and am trying to write a broccoli fractal code however
> I'm having problems with the translate function. If I understood it correctly,
> translate only accepts numerical values. I tried writing a macro but that didn't
> work either. How am I supposed to write a recursive function that utilizes
> translate? :/ Here is my code:
>

Welcome to POV! Hope you'll have as much fun as I've had.

I don't do many recursive macros. But I do see that one problem is the i loop is
in a cone so you have a n-1 cones with 100 closing }. You can't put cones in
cones that way.

The #macro trans() look alright, the i and ang variables are #declare  before
it's called. That works fine. But when we write a macro we usually feed values
to it. Like #macro trans(C,A) and use C & A in the macro. It just help you keep
track of what the macro needs and makes the macro more mobile.

There is a lot more that macros can do. Read the documentation! There is a lot
to POV. I'm still learn something new once in awhile and been at it for over 30
years.

Come to think of it, do a search for POV recursive macros and there is probable
a few complete macros you can use.

Hoped I helped in a small way.

Have Fun!


Post a reply to this message

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