Finding effective directive of a graphics primitive
- To: Mathematica user's group <MathGroup at yoda.physics.unc.edu>
- Subject: Finding effective directive of a graphics primitive
- From: Robby Villegas <Villegas at knox.bitnet>
- Date: Wednesday, May 20 1992
Hello, I have a nested list of graphics primitives and directives, of the kind that Graphics and Graphics3D can accept in the first position, and I would like a function to determine for me what color directive (GrayLevel, RGBColor, Hue, CMYKColor, or whatever) will apply to a particular Line object, which can be buried anywhere in the nested list. As I understand directives (correct me if I am wrong), if there are directives preceding the Line object in the list where the Line sits, then the "most recent" one will determine the style of the line, where "most recent" means closest to the Line in the list ordering, and preceding the Line. If there are no directives for a Line primitive in the list, then if the list itself is an element of a higher list, the elements preceding it in the higher list are checked to see if any apply to a Line. If so, the most recent, again, is the effective one. So if we had {RGBColor[1, 0, 1], GrayLevel[0.8], {Hue[1/3], Line[somepoints]}} the color Hue[1/3] would override, but if we had {RGBColor[1, 0, 1], GrayLevel[0.8], {PointSize[0.02], Line[somepoints]}} there would be none at the same level as the Line, so the GrayLevel from one level up would apply, overriding the RGBColor before it. And so on, up the levels of the nested expression until something is found. I am interested to know an efficient and/or elegant way to locate this "most recent" color directive (or any aspect of style, for that matter), so that given any particular Line in the expression (say defined by its part-specification) I can ask "How will it be rendered, color-wise?" and get the right answer. I've thought about using a loop (maybe Until or For) to backtrack through the elements at each level and ascend the levels until the first matching directive is found. But I've wondered if it would be more efficient or elegant to just generate all the predecessor elements at all levels and extract the valid Line directives from it (probably with Cases), taking the last of these to be the one. Any suggestions on the best implementation of either of these, or better yet a really simple and elegant way to locate what I want? Robby Villegas Knox College (Villegas at Knox.Bitnet)