Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Reading Directive Values

  • To: mathgroup at smc.vnet.net
  • Subject: [mg90833] Re: Reading Directive Values
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Fri, 25 Jul 2008 06:18:41 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <1766B32F-CC9E-4A39-9FC7-D5BE3BFBE490@amherst.edu> <g69fvv$iid$1@smc.vnet.net>

Andy Anderson wrote:

> I would like to be able to define graphics objects whose color  
> scheme, lighting, etc. might be changed by graphics directives in an  
> "informed" way. In order to do this, I need to be able to read the  
> current state of graphics directives. What I need is a function like  
> OptionValue, but I can't find one after substantial perusal of  
> official and unofficial documentation.
> 
> For example, I'd like to be able to define something along these lines:
> 
> 	pg = {If[DirectiveValue[Hue][[3]] <= 0.3, Brown, Sequence[],  
> Yellow], Polygon[{{1, 0, 0}, {1, 1, 1}, {0, 0, 1}}]} ;
> 
> so that
> 
> 	Graphics3D[pg]
> 	Graphics3D[{Red, pg}]
> 	Graphics3D[{Black, pg}]
> 
> would produce yellow, red, and brown polygons.
> 
> Any suggestions?

A graphic is an expression as is everything in Mathematica. Therefore, 
one can use functions such as *Cases[]* to extract specific information 
from a graphic object.

Below, the inner Cases[] seeks out expressions with head "Directive" and 
returns a list of such expressions. The outer cases looks for 
expressions with heads matching the second argument of the function, 
this within the list previously returned by the inner Cases[].


     In[1]:= DirectiveValue[g_, d_Symbol] :=
                Cases[Cases[g, r_Directive, Infinity],
                  d[a__] -> a, Infinity]

             g = Plot3D[Im[ArcSin[(x + I y)^4]], {x, -2, 2}, {y, -2, 2},
                   Mesh -> None, PlotStyle -> Directive[Yellow,
                   Specularity[White, 20], Opacity[0.8]],
                   ExclusionsStyle-> {None, Red}]

             DirectiveValue[g, Opacity][[1]]

             DirectiveValue[g, Specularity][[2]]

     Out[2]= <... graphic deleted ...>

     Out[3]= 0.8

     Out[4]= 20

HTH,
-- Jean-Marc


  • Prev by Date: Re: several plots in manipulate
  • Next by Date: Re: Solving 3d degree polynomial
  • Previous by thread: Reading Directive Values
  • Next by thread: Reading Directive Values