POV-Ray : Newsgroups : povray.binaries.images : macros Server Time
4 Oct 2024 01:13:52 EDT (-0400)
  macros (Message 1 to 7 of 7)  
From: Nobot
Subject: macros
Date: 7 May 1999 20:32:00
Message: <373377AB.5E9D14BE@powersurfr.com>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
I know this is the wrong place, but I lost the addys for the other places
to post.
<br>but where can i get more info on macros and how to make them?
<br> </html>


Post a reply to this message

From: Thomas Lake
Subject: Re: macros
Date: 8 May 1999 00:16:01
Message: <3733AC7F.89258520@home.com>
addys? Anyway I too would be interested in info on making/understanding
macros.

Nobot wrote:

> I know this is the wrong place, but I lost the addys for the other
> places to post.
> but where can i get more info on macros and how to make them?
>


Post a reply to this message

From: Phil Clute
Subject: Re: macros
Date: 8 May 1999 02:42:58
Message: <3733D055.706F9A32@tiac.net>
There's macro info kind of scattered around the newsgroups:

1.In povray.general look for the subject title "Macro tutorial"
  started by Andrew Cocker.
2.In povray.unofficial.patches  "POV+for()" TonyB
  (Really you just want the end of this thread)
3.You may also want to look through povray.utilities which has
  several examples of macros, for example: "Replace macro" "The most
  unuseful macro" and "Useless macro challenger"(which I found a use
  for <smile>).
4.And of course the povray help file...

If what your really looking for is an all-in-one website tutorial I
haven't come across one yet. Maybe Ken has something?

-- 
...coffee?...yes please! extra sugar,extra cream...Thank you.


Post a reply to this message

From: Ken
Subject: Re: macros
Date: 8 May 1999 02:56:35
Message: <3733D179.9D35B140@pacbell.net>
Phil Clute wrote:

> If what your really looking for is an all-in-one website tutorial I
> haven't come across one yet. Maybe Ken has something?

  Nope. I'm still waiting for one of you guy's to write one so I can
link to it :) I am a newbie with macro's myself and would not even presume
to know enough on the subject to be able write one myself. I seem to be
able to use them just fine though if that is any consolation.

-- 
Ken Tyler

mailto://tylereng@pacbell.net


Post a reply to this message

From: Steve
Subject: Re: macros
Date: 8 May 1999 08:17:00
Message: <37341CEE.288D4A82@ndirect.co.uk>
<Gasp>   <Step back in Amazement>  <Come Down To Earth>

I've just written a macro tutorial for this guy or gal, it's not
an all inclusive everythink you did or didn't want to know about
macros, bit it would sure get you started.  I hope it's
understandable, as there have been some answers to Nobot's post,
I'll post my so-called tutorial here in this message.

As a rule I've stopped participating in threads that aren't
relevant to this group, and If I have information I post it
direct to the person and point out the error of their wary.  But
you guys have driven me to it, now I've broken my own rules.

Oh well here goes..... Coments, suggestions, insults, hard cash
all welcome.

Cheers
Steve

PS: Ken, (or whoever), I'm sure my use of Seed/Rand in the second
macro example is incorrect, though it does work here, have tried
exactly the same format in other instances and it just won't work
(example in rotating the chips in the stack randomly). 




Nobot

You are correct, this isn't the correct NG,  povray.general would
be the best place to put this king of message.

Now for your sins you can be the guinea-pig for my Macro
Tutorial.

1.  What Is A Macro And Why Would I Use It?

A macro is a set of instructions which replicates a set of
instructions which you would use repetitively.  So instead of
typing out or copying a group of instructions over and over
again, you include those instructions in a macro and call that
macro when you require those particular instructions.  It's a bit
like the memory on a telephone, instead of dialling the number
for the Pizza shop every day you just press the hash key and the
number one and make your order.  

A macro also gives you the level of flexibility that you would
have if writing out the code over and over again, you ad
variables such as a distance, colour, rate of rotation or size,
these variables can be any variable that you would use in POV. A
variable being anything that you can vary/change, such as the
size of an object. 


2.  How Do I Call The Macro / Make It Work?

I have included a scene below which you can copy and paste into
POV, and experiment with it.  I will use the first macro in this
scene as my example here.  

The first macro in the scene creates a sphere with a colour map. 
The macro is called StripyBall.  You would call/invoke the macro
by typing:

object{
          StripyBall( x, Green, Orange, Yellow, 0.3)
          translate < wherever you want the sphere to appear >
         }

Or you could just type:

StripyBall( x, Green, Orange, Yellow, 0.3)

In the first macro calling example you can place the sphere where
you want it, but in the second example it will always appear in
the same place so the first example is preferable, though you
could have the position as one of the variables that you send to
the macro.

So taking the first example.  "object{" is just opening an object
StripyBall is the name of the macro that we want to call, then
within the brackets "( )" the variables are stated.  These
variables must be in the correct order ie, they must be in the
order that the macro is expecting them to be.  This will become
more clear later on.  The variables that this macro takes are the
gradient that you want the colour map to be applied to, the three
colours that you want to include in the colour map, and finally
the amount of turbulence that you want each sphere to have in
it's colour map.

Each of the variables within the brackets (excluding the last
variable) must have a coma "," after them, if comas are left out
you will get an error message and your scene won't render.


3.  How Do I Build A Macro?

First start by giving your macro a relevant name such as
StripyBall and tell the macro which variables to receive,  be
sure to give these variables relevant names, it will help when
making modifications at a later date.  

This would be a typical first line for a macro and is the first
line of the StripyBall macro:

#macro StripyBall(ballgrade, colour1, colour2, colour3, mixing)

A macro always finishes with the line:

#end

In the above example #macro tells POV to get ready for a macro
declaration.  StripyBall is the name of the macro.  Next comes
the Brackets and the variables that this particular macro will
use,  ballgrade is taken by the macro and used to apply the
colour map to a gradient (x, y, or z) as in the example in number
2 above the first variable after the brackets is x.  The next
three variables in our macro declaration are used as colours for
the colour map, and the final variable "mixing" is used to apply
a turbulence level to the colour map.  

One important thing to remember particularly when calling macros
is that every variable must be included in the call, even if you
want that variable to remain the same as POV's default.  For
example if we call the macro and leave the variable for
turbulence blank, then we get an error message and the scene
won't render.


4.  Time To Look At A Macro!

There are two macros in a scene below, one is the stripy ball
macro and the other is a more complicated macro which creates a
stack of gambling chips that are stacked randomly.

There are already some macro calls to StripyBall, in the example
scene, fiddle around with the code and see what you can do.

You're on your own with the second macro GChip,  get it to work
and read it, try to understand it, and see how powerful macros
can be.

Any further questions or clarifications required, don't hesitate
to email me:  mailto://sjlen@ndirect.co.uk


Have fun.

Cheers 
Steve

// Stephen Joseph Lenehan 1999

// Macro Demonstration

            
#include "colors.inc"
#include "textures.inc"
#include "shapes.inc"

#version 3.1;  

#default {finish { ambient 0.1 diffuse 0.6 phong 0.6 phong_size
7}}

// ******  Basic objects, camera, plane, lights etc. 
************************    


camera{ 
       location <0,3,-10>
       look_at <0,2,0>
      }     
        
light_source{<600,400,-400> rgb 0.8}

light_source{<-300,500,-400> rgb 0.8}
 
plane{y,-1
      
texture{      
        pigment{Gold}
        
        finish{
               phong 0.8
               reflection 1.0 
               specular 1.0 
               roughness 0.001 
               ambient 0.2 
              }
        }
     
     } 

background {MidnightBlue}

#macro StripyBall(ballgrade, colour1, colour2, colour3, mixing)
  sphere{
         <0,2,0>,1.5          
         pigment{
                 gradient ballgrade
                 color_map{
                           [0.0 color colour1]
                           [0.2  color colour2]
                           [0.5  color colour3]
                           [0.8 color colour2]
                           [1.0  color colour1]
                          }          // End of colour map.
                 turbulence mixing
                 scale 0.25
                }           // End of pigment.

        }   // End of sphere.
        
#end    // end of macro StripyBall.


    
object{
       StripyBall(x, Orange, White, Blue, 0.9)
      } 

object{
       StripyBall(y, Red, Black, Green, 0.1)
       translate x*-4
      } 
        

object{
       StripyBall(z, CadetBlue, MediumAquamarine, Yellow, 0.5)
       translate x*4
      } 
                    
                    
// ************** A more complicated macro. 
*******************************

#macro GChip(Colour1, Colour2, Colour3, StackHeight)

  #local ctr2=0;
  #local ypos=-0.5;

  #while(ctr2<StackHeight)
        
    #local ctr=0;
                                 
    #local Chip_Sidecut_Sphr =
      sphere{<0,0,0>0.075}    
                             
    #local Chip_Topcut_Cyl =
      cylinder{
               <0,-0.22,0>,
               <0,0.22,0>
               0.065
              }
                           
    #local TextWoodChip =
      texture{
              T_Wood1 
              finish{Shiny}
             }
   
    #local TextChipBase =
      texture{
              pigment{
                      Colour1 
                      filter 0.5
                     }
              finish{Shiny}
             }
        
    #local MatCutout1 =     
      material{
               texture{TextWoodChip}
               texture{
                       pigment{
                               Colour1 
                               filter 0.5
                             
}                                           
                       finish{Shiny}
                      }
              }
  
    #local MatCutout2 =     
      material{
               texture{TextWoodChip}
               texture{
                       pigment{
                               Colour2 
                               filter 0.5
                             
}                                           
                       finish{Shiny}
                      }
              }            

    #local Check_Cyl =
      cylinder{
               <0,-0.22,0>,
               <0,0.22,0>
               0.65
                           
               texture{TextWoodChip}
                           
               texture{
                       pigment{
                               checker
                               color Colour1
                               filter 0.4
                               color Colour2
                               filter 0.4
                              }        
                      
finish{Shiny}                                                               
                     
}                                               
              } 
 
    #declare TheChip =
      difference{
                 cylinder{
                          <0,-0.22,0>,
                          <0,0.22,0>1
                         }

                 cylinder{
                          <0,-0.22,0>,
                          <0,0.22,0>0.75
                          translate y*0.4
                         }

                 cylinder{
                          <0,-0.22,0>,
                          <0,0.22,0>0.75
                          translate y*-0.4
                         }
 
                 object{
                        Check_Cyl
                        translate y*0.39
                       }

                 object{
                        Check_Cyl
                        translate y*-0.39
                       }
    
                 #while(ctr<361)
        
                   object{
                          Chip_Sidecut_Sphr 
                          material{MatCutout1} 
                          translate <1.06,0.1,0> 
                          rotate y*ctr                      
                         }
     
                   object{
                          Chip_Sidecut_Sphr 
                          material{MatCutout1}  
                          translate <1.06,-0.1,0> 
                          rotate y*(ctr+10)
                         }
       
                   object{
                          Chip_Topcut_Cyl
                          material{MatCutout1}
                          translate <0.85,0.43,0>
                          rotate y*ctr
                         } 
      
                   object{
                          Chip_Topcut_Cyl
                          material{MatCutout1}
                          translate <0.85,-0.43,0>
                          rotate y*(ctr+10)
                         } 
       
                   #local ctr = ctr + 20;
    
                   object{
                          Chip_Sidecut_Sphr 
                          material{MatCutout2} 
                          translate <1.06,0.1,0> 
                          rotate y*ctr
                         }
        
                   object{
                          Chip_Sidecut_Sphr 
                          material{MatCutout2} 
                          translate <1.06,-0.1,0> 
                          rotate y*(ctr+10)
                         }
          
                   object{
                          Chip_Topcut_Cyl
                          material{MatCutout2}
                          translate <0.85,0.43,0>
                          rotate y*ctr
                         } 
   
                   object{
                          Chip_Topcut_Cyl
                          material{MatCutout2}
                          translate <0.85,-0.43,0>
                          rotate y*(ctr+10)
                         } 
       
                   #local ctr = ctr + 20;
                
                 #end  // End of inner while loop, part of the
difference. 
               
                 texture{
                         T_Wood1 
                         pigment{
                                 Colour3 
                                 filter 0.5
                                }
                         finish{Shiny}
                        }           
                }  // End of difference "TheChip"   

    #local xpos=seed(1);
    #local zpos=seed(1);
    #local xpos=rand(xpos);
    #local zpos=rand(zpos);  
    
    object{
           TheChip  
           translate <rand(xpos)/3, ypos, rand(zpos)/3>
          }
    
    #local ypos=ypos+0.44;   
    #local ctr2=ctr2+1;
      
  #end  // End of Chip Stack While loop.

#end  // End of Macre "GChip"


Post a reply to this message

From: Phil Clute
Subject: Re: macros
Date: 8 May 1999 20:03:08
Message: <3734C420.5C4E69B2@tiac.net>
> But you guys have driven me to it, now I've broken my own rules.

I've been trying to keep my discussions in the correct groups.
As you pointed out this really belongs in either general or
text.tutorials.

Thanks for the info, I'm still learning this stuff so the examples
will come in handy when I find a little time to try them out.

Phil
-- 
...coffee?...yes please! extra sugar,extra cream...Thank you.


Post a reply to this message

From: Steve
Subject: Re: macros
Date: 9 May 1999 14:05:00
Message: <3735BA5C.D6A25065@ndirect.co.uk>
Example two won't work as is, you will need to put the line:
   
    #include "woods.inc"

at the top of the file.  

Phil Clute wrote:
> 
> > But you guys have driven me to it, now I've broken my own rules.
> 
> I've been trying to keep my discussions in the correct groups.
> As you pointed out this really belongs in either general or
> text.tutorials.
> 
> Thanks for the info, I'm still learning this stuff so the examples
> will come in handy when I find a little time to try them out.
> 
> Phil
> --
> ...coffee?...yes please! extra sugar,extra cream...Thank you.


Post a reply to this message

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