Message Boards Message Boards

GROUPS:

[GIF] Inertia (Distorted grid)

Posted 3 years ago
4231 Views
|
2 Replies
|
10 Total Likes
|

Distorted grid

Inertia

Back to the broken grids.

The code is kind of unpleasant because I was having trouble adapting my initial monochromatic code to allow the dots and lines to have variable colors. Presumably there's a cleaner way of doing this, but I just bolted the colors on rather than re-writing.

DynamicModule[{cols, grid},
 cols = RGBColor /@ {"#B463A6", "#00C3FF", "#3B475E"};
 Manipulate[
  grid = Table[{Blend[cols[[;; -2]], 
        Haversine[Clip[2 #, {0, 2 π}]]], 
       RotationMatrix[π/2 Haversine[Clip[ #, {0, π}]]].{x, 
         y}} &[t - π Norm[{x, y}]/Sqrt[50]], {x, -8, 8}, {y, -8, 8}];
  Graphics[{Table[{grid[[i + 9, j + 9, 1]], 
      Disk[grid[[i + 9, j + 9, 2]], .1]}, {i, -8, 8}, {j, -8, 8}], 
    Thickness[.005], 
    Line[#[[;; , ;; , 2]], VertexColors -> #[[;; , ;; , 1]]] &[
     Table[grid[[i + 9]], {i, -8, 8}]], 
    Line[#[[;; , ;; , 2]], VertexColors -> #[[;; , ;; , 1]]] &[
     Table[grid[[;; , j + 9]], {j, -8, 8}]]}, PlotRange -> 5, 
   ImageSize -> 540, Background -> cols[[-1]]],
  {t, 0, 2 π}]
 ]
2 Replies
Posted 3 years ago

GraphicsComplex[] helps a fair bit in simplifying the code given below. The only snag is that altho GraphicsComplex[] takes a VertexColors setting, Disk[] is unaffected by it, which necessitates having to keep two copies of the colors:

With[{n = 5},
     Manipulate[Graphics[With[{cl = Flatten[Table[Blend[{RGBColor["#B463A6"], RGBColor["#00C3FF"]}, 
                                                        Haversine[Clip[2 (t - π Norm[{x, y}]/Sqrt[50]), {0, 2 π}]]],
                                                  {x, -n - 2, n + 2}, {y, -n - 2, n + 2}]]},
                              GraphicsComplex[Flatten[
                              Table[RotationMatrix[π Haversine[Clip[t - π Norm[{x, y}]/Sqrt[50], {0, π}]]/2].{x, y},
                                   {x, -n - 2, n + 2}, {y, -n - 2, n + 2}], 1],
                              {Thickness[0.005], Line[(# ~Join~ Transpose[#]) &[Partition[Range[(2 n + 5)^2], 2 n + 5]],
                                                      VertexColors -> Automatic],
                                Riffle[cl, Table[Disk[k, 0.1], {k, (2 n + 5)^2}]]}, VertexColors -> cl]], 
                            Background -> RGBColor["#3B475E"], ImageSize -> 540, PlotRange -> n], {t, 0, 2 π}]]
POSTED BY: J. M.
Answer

enter image description here - another post of yours has been selected for the Staff Picks group, congratulations !

We are happy to see you at the top of the "Featured Contributor" board. Thank you for your wonderful contributions, and please keep them coming!

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract