# mesh vertex coloring

So I created a mesh like this:

mesh2 = ToElementMesh[FullRegion[2], {{1, 10}, {1, 10}}, MaxCellMeasure -> 1.];


and want to plot it, coloring the squares:

Show[Graphics[ElementMeshToGraphicsComplex[mesh2, All,VertexColors -> {Red, Green, Red}]], mesh2["Wireframe"]]


What I get is this:

Now what I'd like is to color my squares homogeneously, i.e. I don't want the fancy fading effect from one square to the other, all I need is simple, even colors.

Thanks!

Some cheating necessary:

<< NDSolveFEM
mesh = ToElementMesh[FullRegion[2], {{1, 10}, {1, 10}}, MaxCellMeasure -> 1.];
Show[Graphics[Riffle[Flatten[Normal[ElementMeshToGraphicsComplex[mesh, All]]],
{Red, Green}, {1, -1, 2}]], mesh["Wireframe"]]


• Thanks! Could you please add a little explanation about what's going on? Especially with the Riffle[]... – botond Oct 20 '15 at 17:24
• Normal[] is the usual way to convert a GraphicsComplex[] object into a list of graphics primitives with explicit coordinates. As for the Riffle[] bit: ponder on the result of Riffle[Range[7], {Red, Green}, {1, -1, 2}]. – J. M.'s torpor Oct 20 '15 at 17:31

Add markers to the QuadElement of the mesh, a list alternating 1/2 equal in length to the number of elements (vis Mod[Range@Length@q, 2, 1]):

Needs["NDSolveFEM"];
mesh2 = ToElementMesh[FullRegion[2], {{1, 10}, {1, 10}}, MaxCellMeasure -> 1.] /.


Then we can color each of the two markers independently:

mesh2["Wireframe"["MeshElementStyle" -> {FaceForm[Red], FaceForm[Green]}]]


Like J.M.'s answer, it assumes that the elements come in a certain order. The order can be inspected as follows. The following shows the order of the elements:

 mesh2["Wireframe"["MeshElementIDStyle" -> Red]]


The following shows the markers:

mesh2["Wireframe"["MeshElementMarkerStyle" -> Blue]]


See the tutorial Element Mesh Visualization for more on visualizing meshes.