POV-Ray : Newsgroups : povray.newusers : Help with writing functions... Server Time
3 Jul 2024 01:58:30 EDT (-0400)
  Help with writing functions... (Message 1 to 3 of 3)  
From: Ryan Abrahams
Subject: Help with writing functions...
Date: 21 Jul 2010 04:20:00
Message: <web.4c46acbefbb26d6c611a67e40@news.povray.org>
Hi All,

I have been attempting to write a simple function to help me with making quick
and dirty solar system models...

I have attempted to read the user defined function manual, but it doesn't really
go into much detail, or give examples of anything more than a one line function.


You can probably tell what I want to do with this function (does not run!)


#declare drawPlanet = function(siz, rads, ang, col)
{
   xcord = rads * cos(ang * (pi / 180) )
   zcord = rads * sin(ang * (pi / 180) )

   sphere
   {
      <xcord, 0, zcord>, siz
      texture { pigment col } }

   }

}


If I #declare xcord, then I will get an error message, because I can not use an
uninitialized identifier. From what I could tell, #declares are more one off
variables, or globals, rather than function specific.

Without the #declare in xcoord, I get:

File Context (5 lines):
   xcord = rads * cos(ang * (pi / 180) )
   zcord
Parse Error: Expected 'operator', undeclared identifier 'zcord' found instead.


I am not sure if there is a specific way you declare a temporary float in povray
(say in C you would have float $xcoord, or so on... my C is pretty rusty too!)


Considering I have to do about 40 of these basic systems, I'd hate to have to
create each system by hand, rather than using a simple function like this.


If there is any other documentation on function writing, I found this page
(http://www.povray.org/documentation/view/3.6.1/231/) did not give enough info
for me to be able to work it out on my own :)

Ryan


Post a reply to this message

From: Slime
Subject: Re: Help with writing functions...
Date: 21 Jul 2010 04:28:12
Message: <4c46af9c@news.povray.org>
> I have attempted to read the user defined function manual, but it 
doesn't really
 > go into much detail, or give examples of anything more than a one 
line function.

That's because functions don't support what you're trying to do. They 
only support simple mathematical expressions. You probably want to make 
a #macro instead. Then #declare will work.

#macro drawPlanet(siz, rads, ang, col)
     #declare xcord = rads * cos(ang * (pi / 180) );
     #declare zcord = rads * sin(ang * (pi / 180) );

     sphere
     {
        <xcord, 0, zcord>, siz
        texture { pigment { col } }
     }
#end


  - Slime


Post a reply to this message

From: Warp
Subject: Re: Help with writing functions...
Date: 21 Jul 2010 08:53:07
Message: <4c46edb2@news.povray.org>
Ryan Abrahams <nomail@nomail> wrote:
> I have attempted to read the user defined function manual, but it doesn't really
> go into much detail, or give examples of anything more than a one line function.

  That's because user-defined functions do not support anything else than
what is documented.

  What you are looking for is the #macro feature.

-- 
                                                          - Warp


Post a reply to this message

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