9
$\begingroup$

The code below is to create something like a logo. I want to apply a color gradient over the polygons of the pattern, but they vary along the path. The image that I want to approach is this:

enter image description here

ang = 66 Degree; h = 70; esp = 20.5;
p1 = {0, 0};
p2 = {h/Tan[ang], h};
p3 = {p2[[1]] + esp/Sin[ang], h};
p4 = {p1[[1]] + esp/Sin[ang], 0};
shift = {p3[[1]] - esp, 0};
rectangle = Polygon[{{0, 0}, {esp, 0}, {esp, h}, {0, h}}];
parallelogram = Polygon[{p1, p2, p3, p4}];
parallelogram2 = GeometricTransformation[
   parallelogram,
       { 
        {{1, 0}, {0, -1}}, 
        {0, h} + {p2[[1]], 0} + 4 shift
        }
       ];
Graphics[
 {
  EdgeForm[{Thick, Black}], FaceForm[Gray],
  Table[Translate[rectangle, i shift], {i, 1, 4}],
  parallelogram2,
  EdgeForm[{Thick, Black}], FaceForm[White],
  Table[Translate[parallelogram, i shift], {i, 0, 4}]
  }
 ]

enter image description here

I believe the Blend function is the best option, but I do not understand how to apply it ...

EDIT

I liked KennyColnago's solution, but I'm still looking for something closer to the image.

In an attempt to approach the solution I tried at least to define the four colors of each corner of the polygons. Below the pixels of the first polygon ...

g1 = {{3, 2}, {50, 2}, {74, 155}, {117, 155}};

enter image description here

That way I got all 20 pixels. Four pixels for each of the five front polygons ...

corners = 4;
g1 = {{3, 2}, {50, 2}, {74, 155}, {117, 155}};

img = Import[
   "C:\\Users\\Leandro\\Desktop\\Image.png"];

Map[RGBColor, 
 Map[PixelValue[img, #] &, 
  NestList[Plus[# + Table[{71, 0}, corners]] &, g1, 
   corners], {2}], {2}]

enter image description here

$\endgroup$
  • $\begingroup$ related: 31131, 6562 $\endgroup$ – Kuba Jul 21 '17 at 11:40
  • $\begingroup$ @Kuba The RoundedBlock function approaches the link because it has the idea of shadow ... $\endgroup$ – LCarvalho Jul 21 '17 at 14:12
13
$\begingroup$

I like the dimensionality suggested by VertexColors. Given your definitions of ang ... parallelogram2, I tried variations of colour schemes such as the following.

Graphics[{
   EdgeForm[{Thick, Black}],
   Table[
      Translate[rectangle, i*shift] /. 
         Polygon[x_List] :> 
           Polygon[x, VertexColors -> 
              Map[ColorData["SolarColors", #] &, Range[i/6, 0, -i/12]]],
      {i, 1, 4}],
   {parallelogram2 /. 
       Polygon[x_List] :> 
          Polygon[x, VertexColors -> 
             Table[Lighter[ColorData["RoseColors", k], 0.7],
                {k, {0.35, 0.57, 0.78, 1.}}]]},
   Table[
      Translate[parallelogram, i*shift] /. 
         Polygon[x_List] :> 
            Polygon[x, VertexColors -> 
               Map[Lighter[ColorData["RoseColors", #], i/6] &, 
                   Range[0.7 - i*0.05, 1, (0.3 + i*0.05)/3]]],
      {i, 0, 4}]
}]

logo with VertexColors

$\endgroup$
  • $\begingroup$ Are coming. The shadow is fundamental ... $\endgroup$ – LCarvalho Jul 21 '17 at 15:59
  • $\begingroup$ Today I finished my activities, but on 24.07 I will resume analyzing the colors of the drawing through Photoshop. It would be better through Mathematica, but I still do not have the ability ... $\endgroup$ – LCarvalho Jul 21 '17 at 17:03
6
$\begingroup$
col = Table[Blend[{RGBColor[1, 0, 0, 1], RGBColor[0, 1, 0, 0]}, x], {x, 0, 1, 1/11}];

Graphics[{
  EdgeForm[{Thick, Black}],
  Table[{FaceForm[col[[2 n - 1]]], Translate[rectangle, n shift]}, {n,1, 4}],
  Table[{FaceForm[col[[2 n]]], Translate[parallelogram, (n - 1) shift]}, {n, 1, 5}],
  {FaceForm[col[[11]]], parallelogram2}}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.