• To: mathgroup at smc.vnet.net
• Subject: [mg90862] Reading Directive Values
• From: Andy Anderson <aanderson at amherst.edu>
• Date: Sat, 26 Jul 2008 04:24:10 -0400 (EDT)
• References: <02B22C12-1A92-4F47-B450-3E8338116517@amherst.edu>

On Jul 24, 2008, at 12:48 PM, Jean-Marc Gulliet wrote:

> 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

Thanks for the suggestion. This would work for me if the directive is
assigned to a symbol, but in common use they aren't, as in my
examples such as Graphics3D[{Red, pg}]. Mathematica or rather Graphics
(3D) tucks their values away somewhere, similar to Sow[], and then
applies that to each subsequent graphic, as if with Reap[].

-- Andy

• Prev by Date: Possible bug in Fits.exe on Mac OSX Mathematica 6.0.3
• Next by Date: Re: Text search within a documentation page?