Group Abstract Group Abstract

Message Boards Message Boards

[GIF] Bounce ((3,1)+(1,3) vibration mode of a square membrane)

4 Replies

As usual great stuff!

While it is not fun to write for everyone I knew I need to try to optimize it. To my surprise I was able to make it smooth and completely FE side which means you can use it e.g. as a progress indicator:

\[CapitalPsi][m_, n_, {x_, y_}] := Sin[m \[Pi] x] Sin[n \[Pi] y];
DynamicModule[
 {n = 20, a = 1.2, dots, 
  cols = RGBColor /@ {"#0098d8", "#f54123", "#0b3536"}, \[Theta], 
  colorGrid, cf},
 dots = Table[{(*we can pregenerate the table and leave z coordinate \
'dynamic'*)
    2 \[Pi] (x - 1)/n,
    2 \[Pi] (y - 1)/n,
    Cos[Dynamic[
       2 Pi \[Theta]]] ((*we are preparing 'dynamic placeholder' to \
be used later. the rescaling to 0-2Pi done here can be done FE side.*)


      1./Sqrt[2] \[CapitalPsi][3, 1, {(x - 1)/n, (y - 1)/n}] + 
       1/Sqrt[2] \[CapitalPsi][1, 3, {(x - 1)/n, (y - 1)/n}]
      )
    }, {x, 1, n + 1}, {y, 1, n + 1}];

 Overlay[{
   Animator[ Dynamic[\[Theta]], AppearanceElements -> None, 
    AnimationRate -> 1],
   Graphics3D[{
     AbsoluteThickness[2],
     Table[With[{i = i},
         Line[#[[i]], VertexColors -> (
            Function[dynH,

              RGBColor[(*'manual blend' because FE can handle basic \
arithmetic and not Blend itself. InputForm/@RGBColor/@{"#0098d8",
               "#f54123","#0b3536"} *) 
               0.9607843137254902 (dynH + a)/(2. a),

               0.596078431372549 + (0.2549019607843137 - 
                   0.596078431372549) (dynH + a)/(2. a),

               0.8470588235294118 + (0.13725490196078433 - 
                   0.8470588235294118) (dynH + a)/(2. a)
               ],
              Listable
              ]@#[[i, ;; , 3]]
            )]
         ],
        {i, Length[#]}
        ] & /@ {dots, Transpose[dots]}
     },
    Boxed -> False, 
    PlotRange -> {{0, 2 \[Pi]}, {0, 2 \[Pi]}, {-2, 2}}, 
    ImageSize -> 540, ViewPoint -> {2, 0, 1/2}, 
    SphericalRegion -> True, Background -> cols[[-1]]]
   }, All, 2],
 Initialization :> (\[Theta] = 0)
 ]
POSTED BY: Kuba Podkalicki

Very cool!

Thanks. Overlay corrected so you can rotate it live now :)

POSTED BY: Kuba Podkalicki

enter image description here - Congratulations! This post is now a Staff Pick as distinguished by a badge on your profile! Thank you, keep it coming, and consider contributing your work to the The Notebook Archive!

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