Skip to main content
added 1 character in body
Source Link
xzczd
  • 71.6k
  • 10
  • 183
  • 524

OK, sinesince my rewording

If I only want to use one single Polygon[…] for multiple polygons, how can I style them separately in a simpler way?

has been approved by OP, here's my solution:

colored[p_Polygon, colorlst_ : ColorData[97, "ColorList"]] := With[{pointlst = p[[1]]}, Append[p, VertexColors -> MapThread[ Table, {PadRight[{}, Length@pointlst, colorlst], Length /@ pointlst}]]] 

Alternatively, use the new-in-14.3 Cyclic, which makes the code slightly shorter, but slightly slower:

colored[p_Polygon, colorlst_ : ColorData[97, "ColorList"]] := With[{pointlst = p[[1]]}, Append[p, VertexColors -> MapIndexed[Table[Cyclic[colorlst]@#2[[1]], Length@#] &, pointlst]]] 

Usage:

polycollection = Polygon[Append[ Table[RotationMatrix[n Pi/3] . # & /@ {{0, 0}, {1, 0}, {1/2, Sqrt[3]/2}}, {n, 0, 5}], {{1, 1}, {2, 1}, {2, 2}, {1, 2}}]]; colored@polycollection // Graphics 

enter image description here

polycollection~colored~{Orange, LightBlue, DarkGreen} // Graphics 

enter image description here

OK, sine my rewording

If I only want to use one single Polygon[…] for multiple polygons, how can I style them separately in a simpler way?

has been approved by OP, here's my solution:

colored[p_Polygon, colorlst_ : ColorData[97, "ColorList"]] := With[{pointlst = p[[1]]}, Append[p, VertexColors -> MapThread[ Table, {PadRight[{}, Length@pointlst, colorlst], Length /@ pointlst}]]] 

Alternatively, use the new-in-14.3 Cyclic, which makes the code slightly shorter, but slightly slower:

colored[p_Polygon, colorlst_ : ColorData[97, "ColorList"]] := With[{pointlst = p[[1]]}, Append[p, VertexColors -> MapIndexed[Table[Cyclic[colorlst]@#2[[1]], Length@#] &, pointlst]]] 

Usage:

polycollection = Polygon[Append[ Table[RotationMatrix[n Pi/3] . # & /@ {{0, 0}, {1, 0}, {1/2, Sqrt[3]/2}}, {n, 0, 5}], {{1, 1}, {2, 1}, {2, 2}, {1, 2}}]]; colored@polycollection // Graphics 

enter image description here

polycollection~colored~{Orange, LightBlue, DarkGreen} // Graphics 

enter image description here

OK, since my rewording

If I only want to use one single Polygon[…] for multiple polygons, how can I style them separately in a simpler way?

has been approved by OP, here's my solution:

colored[p_Polygon, colorlst_ : ColorData[97, "ColorList"]] := With[{pointlst = p[[1]]}, Append[p, VertexColors -> MapThread[ Table, {PadRight[{}, Length@pointlst, colorlst], Length /@ pointlst}]]] 

Alternatively, use the new-in-14.3 Cyclic, which makes the code slightly shorter, but slightly slower:

colored[p_Polygon, colorlst_ : ColorData[97, "ColorList"]] := With[{pointlst = p[[1]]}, Append[p, VertexColors -> MapIndexed[Table[Cyclic[colorlst]@#2[[1]], Length@#] &, pointlst]]] 

Usage:

polycollection = Polygon[Append[ Table[RotationMatrix[n Pi/3] . # & /@ {{0, 0}, {1, 0}, {1/2, Sqrt[3]/2}}, {n, 0, 5}], {{1, 1}, {2, 1}, {2, 2}, {1, 2}}]]; colored@polycollection // Graphics 

enter image description here

polycollection~colored~{Orange, LightBlue, DarkGreen} // Graphics 

enter image description here

Simplify the code a bit
Source Link
xzczd
  • 71.6k
  • 10
  • 183
  • 524

OK, sine my rewording

If I only want to use one single Polygon[…] for multiple polygons, how can I style them separately in a simpler way?

has been approved by OP, here's my solution:

colored[p_Polygon, colorlst_ : ColorData[97, "ColorList"]] := With[{pointlst = p[[1]]}, Append[p, VertexColors -> MapThread[ Table, {PadRight[colorlstPadRight[{}, Length@pointlst, colorlst], Length /@ pointlst}]]] 

Alternatively, use the new-in-14.3 Cyclic, which makes the code slightly shorter, but slightly slower:

colored[p_Polygon, colorlst_ : ColorData[97, "ColorList"]] := With[{pointlst = p[[1]]}, Append[p, VertexColors -> MapIndexed[Table[Cyclic[colorlst]@#2[[1]], Length@#] &, pointlst]]] 

Usage:

polycollection = Polygon[Append[ Table[RotationMatrix[n Pi/3] . # & /@ {{0, 0}, {1, 0}, {1/2, Sqrt[3]/2}}, {n, 0, 5}], {{1, 1}, {2, 1}, {2, 2}, {1, 2}}]]; colored@polycollection // Graphics 

enter image description here

polycollection~colored~{Orange, LightBlue, DarkGreen} // Graphics 

enter image description here

OK, sine my rewording

If I only want to use one single Polygon[…] for multiple polygons, how can I style them separately in a simpler way?

has been approved by OP, here's my solution:

colored[p_Polygon, colorlst_ : ColorData[97, "ColorList"]] := With[{pointlst = p[[1]]}, Append[p, VertexColors -> MapThread[ Table, {PadRight[colorlst, Length@pointlst, colorlst], Length /@ pointlst}]]] 

Alternatively, use the new-in-14.3 Cyclic, which makes the code slightly shorter, but slightly slower:

colored[p_Polygon, colorlst_ : ColorData[97, "ColorList"]] := With[{pointlst = p[[1]]}, Append[p, VertexColors -> MapIndexed[Table[Cyclic[colorlst]@#2[[1]], Length@#] &, pointlst]]] 

Usage:

polycollection = Polygon[Append[ Table[RotationMatrix[n Pi/3] . # & /@ {{0, 0}, {1, 0}, {1/2, Sqrt[3]/2}}, {n, 0, 5}], {{1, 1}, {2, 1}, {2, 2}, {1, 2}}]]; colored@polycollection // Graphics 

enter image description here

OK, sine my rewording

If I only want to use one single Polygon[…] for multiple polygons, how can I style them separately in a simpler way?

has been approved by OP, here's my solution:

colored[p_Polygon, colorlst_ : ColorData[97, "ColorList"]] := With[{pointlst = p[[1]]}, Append[p, VertexColors -> MapThread[ Table, {PadRight[{}, Length@pointlst, colorlst], Length /@ pointlst}]]] 

Alternatively, use the new-in-14.3 Cyclic, which makes the code slightly shorter, but slightly slower:

colored[p_Polygon, colorlst_ : ColorData[97, "ColorList"]] := With[{pointlst = p[[1]]}, Append[p, VertexColors -> MapIndexed[Table[Cyclic[colorlst]@#2[[1]], Length@#] &, pointlst]]] 

Usage:

polycollection = Polygon[Append[ Table[RotationMatrix[n Pi/3] . # & /@ {{0, 0}, {1, 0}, {1/2, Sqrt[3]/2}}, {n, 0, 5}], {{1, 1}, {2, 1}, {2, 2}, {1, 2}}]]; colored@polycollection // Graphics 

enter image description here

polycollection~colored~{Orange, LightBlue, DarkGreen} // Graphics 

enter image description here

Source Link
xzczd
  • 71.6k
  • 10
  • 183
  • 524

OK, sine my rewording

If I only want to use one single Polygon[…] for multiple polygons, how can I style them separately in a simpler way?

has been approved by OP, here's my solution:

colored[p_Polygon, colorlst_ : ColorData[97, "ColorList"]] := With[{pointlst = p[[1]]}, Append[p, VertexColors -> MapThread[ Table, {PadRight[colorlst, Length@pointlst, colorlst], Length /@ pointlst}]]] 

Alternatively, use the new-in-14.3 Cyclic, which makes the code slightly shorter, but slightly slower:

colored[p_Polygon, colorlst_ : ColorData[97, "ColorList"]] := With[{pointlst = p[[1]]}, Append[p, VertexColors -> MapIndexed[Table[Cyclic[colorlst]@#2[[1]], Length@#] &, pointlst]]] 

Usage:

polycollection = Polygon[Append[ Table[RotationMatrix[n Pi/3] . # & /@ {{0, 0}, {1, 0}, {1/2, Sqrt[3]/2}}, {n, 0, 5}], {{1, 1}, {2, 1}, {2, 2}, {1, 2}}]]; colored@polycollection // Graphics 

enter image description here