POV-Ray : Newsgroups : povray.newusers : How to print a color generated by a macro? : Re: How to print a color generated by a macro? Server Time
2 May 2024 10:09:15 EDT (-0400)
  Re: How to print a color generated by a macro?  
From: clipka
Date: 25 Aug 2014 23:41:41
Message: <53fc01f5@news.povray.org>
Am 26.08.2014 04:30, schrieb wealthychef:
> Hi, I have the following macro (simplified for brevity).
>
> #macro ColorFromBurgers(burgers)
> /* good 11-color map from http://colorbrewer2.org
>    #warning concat("Got burgers value: ",str(burgers,0,0),"\n")
> */
>    #switch(burgers)
>   #range (-5,-1)
>     rgb <141,211,199>/255.0
>   #break
>   #case (0)
>     rgb <255,255,179>/255.0
>   #break
>   #case (10)
>     rgb <190,186,218>/255.0
>   #break
> #end
> #end
>
> I want to print out the color my macro is returning somehow.
> I've tried the following with no success:
> First I tried:
> #warning concat("The color is ",ColorFromBurgers(burger),"\n")
> but I get an error about not having three arguments.
> File Context (5 lines):
>            rgb <251,128,114>/255.0
>          #break
>          #case (12)
>            rgb <128,177,211>/255.0
>          #
> Parse Error: Expected 3 parameters but only 1 found.
>
> Strange that none of the lines seems to be anything that needs 3 parameters.

"Returning" values from within control structures in a macro can be 
troublesome; try something like this:

   #macro ColorFromBurgers(burgers)
     #switch(burgers)
       #range(-5,-1)
         #local Result = rgb <141,211,199>/255.0;
       #break
       #case (0)
         #local Result = rgb <255,255,179>/255.0;
       #break
       #case (10)
         #local Result = rgb <190,186,218>/255.0;
       #break
     #end
     Result
   #end


As for printing the result, remember that colours are vector-like 
beasts, so vstr() should do the job.


Post a reply to this message

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