# Applying different color to result of a geometric transformation

Background: consider the following two snippets.

  GeometricTransformation[{Cyan, Polygon[{{0, 0}, {.2, .6}, {.8, .2}}]},
Table[RotationTransform[2 \[Pi] k/6], {k, 0, 5}]] // Graphics


  Table[GeometricTransformation[{Opacity[.15*k], Cyan, Polygon[{{0, 0}, {.2, .6}, {.8,.2}}]},
RotationTransform[2 \[Pi] k/6]], {k, 0, 5}] // Graphics


I make most of my graphics as in the first example. Because that is ( supposedly ) the most efficient way. But I have to add gradient colors ( and other options later ), I found no other way to do it as in the second example.

What I in fact want is this:

  GeometricTransformation[g, {ListOfTransformations}]


where g is some geometry. I want to be able to apply different colors to the transformed g's. But not in the way as done in example 2.

Question: How can I apply a different color to the result of a geometric transformation?

-
A judicious use of Insert[] might be in order... –  Guess who it is. Jun 22 '12 at 15:30
Could you elaborate a bit on that @J.M. , I don't understand what you mean. –  ndroock1 Jun 22 '12 at 15:32

Here is an alternative that tries to use the "listability" of Polygon for both, the points and the colors.

The idea is that all individual polygons and their corresponding (different) colors can be provided as two single lists if we use VertexColors:

Graphics@Polygon[#1, VertexColors -> #2] &[
Table[RotationTransform[
2 Pi k/6][{{0, 0}, {.2, .6}, {.8, .2}}], {k, 0, 5}],
Table[{#, #, #} &@Directive[Cyan, Opacity[.15 k]], {k, 0, 5}]]


Now although I have to supply two separate tables here, I at least need only one single Polygon command. The separate tables aren't such a big problem, I think, because we have gained a simplification in the graphical part of the code (which is often the slowest).

And by using VertexColors, I of course gain some new flexibility that you don't have if you add face colors the "old-fashioned" way. For example, one can do this with only a small modification of the code:

Graphics@Polygon[#1, VertexColors -> #2] &[
Table[RotationTransform[
2 Pi k/6][{{0, 0}, {.2, .6}, {.8, .2}}], {k, 0, 5}],
Table[Directive[Hue[#],
Opacity[.15 (k + 1)]] & /@ ({.1, .2, .3} (k + 1)), {k, 0, 5}]]


-
Re: your website. This is perhaps a less poetic but more faithful translation laudatortemporisacti.blogspot.com.ar/2010/06/… –  belisarius Jun 23 '12 at 2:49
I remember that I have looked at the VertexColors but I discarded it as 'too difficult' ( for me ) at the time. But that was quite some time ago. ;-) –  ndroock1 Jun 23 '12 at 10:30
I was thinking... if a color is assigned at the Vertex level we can add a coordinate ( or more ) that represents the color. I work in 2D so I can for example use a coordinate for the Opacity and can thus change Opacity with a Transformation. –  ndroock1 Jun 23 '12 at 13:16
@belisarius The link on my website was given to me by a Spanish native speaker, but your seems a more literal translation. I feel that the other translation is more sparse and evokative, though. –  Jens Jun 23 '12 at 15:52
@ndroock1 Using the z coordinate to encode opacity - may work but you'd have to start with 3D polygons, post-process them and then remove the z coordinate to get a 2D graphics. Is that really worth it for your application? –  Jens Jun 23 '12 at 15:55

I don't think it is possible to do it as you'd like.

If you examine the FullForm of the graphics made this way (changed a bit to shorten the output) you see the following:

Graphics[GeometricTransformation[Point[{0, 0}],
Table[RotationTransform[k], {k, 2}]]] // FullForm

(* ==>
Graphics[GeometricTransformation[Point[{0, 0}],
{TransformationFunction[
{{Cos[1], -Sin[1], 0}, {Sin[1], Cos[1], 0}, {0, 0, 1}}],
TransformationFunction[
{{Cos[2], -Sin[2], 0}, {Sin[2],Cos[2], 0}, {0, 0, 1}}]}]] *)


The Graphics contains the whole GeometricTransformation construction with only the Table expanded. The implication of this is that GeometricTransformation is a Graphics primitive that is directly rendered by the FrontEnd without being translated into lower primitives. This is, of course, the reason why GeometricTransformation can be very efficient to use. You can have a very complex graphics element and if you copy it, you only store the copy instructions and not as many copies of the complex element itself.

The disadvantage is what you have discovered, you can't change its color or opacity, as these properties are part of the single element's description. As far as I know, there is no Transform type for these properties.

-
Makes sense to me, I was afraid of this. Without GeometricTransformation and Translate the performance of what I did totally collapses. Welcome to the new challenge. ;-) –  ndroock1 Jun 22 '12 at 20:25