1
$\begingroup$

I am using Mathematica 12 on Mac.

I would like to export the following code to a CDF file.

  g1[a_] := ParametricPlot3D[{a*Cos[\[Theta]]*Sin[\[Phi]], 
    a*Sin[\[Theta]]*Sin[\[Phi]], a*Cos[\[Phi]]}, {\[Theta], 0, 
    2 \[Pi]}, {\[Phi], \[Pi]/2, \[Pi]}, Mesh -> 50, 
   MeshStyle -> Opacity[.2], 
   PlotStyle -> {Directive[{Green, Opacity[0.15], Thickness[.005]}]}];

  level = 0;



 p4 = Graphics3D[{Polygon[{{-2.2, -2.2, level}, {-2.2, 2.2, 
           level}, {2.2, 2.2, level}, {2.2, -2.2, level}}]}, 
       Opacity[0.05], Lighting -> "Neutral"];

 shh1 = Manipulate[Show[g1[a], p4], {{a, 1}, 1, 5, 1/50}];

I searched around and found this command:

CDFDeploy["happy.cdf", shh1]

But the output (the happy.cdf) is only a static pictute, without interactive manipulation.

Could anyone help me with a hint?

$\endgroup$
4
  • 1
    $\begingroup$ without interactive manipulation how do you expect this interaction to show up? By itself? You have not done any interactive manipulation in the code you are exporting. You just exported a static image so naturally the CDF will contain a static image. $\endgroup$ – Nasser May 3 '20 at 10:24
  • $\begingroup$ @Nasser I meant that at least we can rotate the image as normal. Did I get a wrong understanding here? So we need to have some manipulation so that the CDF makes sense? $\endgroup$ – Binjiu May 3 '20 at 10:55
  • $\begingroup$ My understanding is that CDF is meant to work only with Dynamic content. Something like Dynamic module or Manipulate. Rotating that content you saved using mouse and such does not work on its own, either if you open the CDF file using the CDF Player or open the CDF file using Mathematica itself. The content needs to be Dynamic for any interaction. $\endgroup$ – Nasser May 3 '20 at 11:22
  • $\begingroup$ @Nasser Hi, Thanks, now I 've modified the code so that we have the function Manipulate. I did try CDFDeploy["happy.cdf", shh1] but it did not work. $\endgroup$ – Binjiu May 3 '20 at 11:33
3
$\begingroup$

now I 've modified the code so that we have the function Manipulate. I did try CDFDeploy["happy.cdf", shh1] but it did not work

This is because the Manipulate you saved did not contain all the functions it needed to run. You need to have everything it needs inside it. One option is to use the Initialization section of Manipulate, or to use SaveDefinitions. I prefer Initialization myself.

shh1 = Manipulate[
   Show[g1[a], p4],
   {{a, 1}, 1, 5, 1/50},
   Initialization :> (
     g1[a_] := 
      ParametricPlot3D[{a*Cos[\[Theta]]*Sin[\[Phi]], 
        a*Sin[\[Theta]]*Sin[\[Phi]], a*Cos[\[Phi]]}, {\[Theta], 0, 
        2 \[Pi]}, {\[Phi], \[Pi]/2, \[Pi]}, Mesh -> 50, 
       MeshStyle -> Opacity[.2], 
       PlotStyle -> {Directive[{Green, Opacity[0.15], 
           Thickness[.005]}]}];
     level = 0;
     p4 = 
      Graphics3D[{Polygon[{{-2.2, -2.2, level}, {-2.2, 2.2, 
           level}, {2.2, 2.2, level}, {2.2, -2.2, level}}]}, 
       Opacity[0.05], Lighting -> "Neutral"]
     )
   ];

    CDFDeploy["happy.cdf", shh1]

Now it works inside CDF player OK

enter image description here

$\endgroup$
3
  • $\begingroup$ It's very knowledgeable. Could you give me one more favor, how could you create the gif. file with your mouse in action like this? $\endgroup$ – Binjiu May 3 '20 at 12:24
  • $\begingroup$ @Binjiu I use screen capture software which saves it to animated GIF file. it is free. It is called LICcap (if you google it you find it). Easy to use also. $\endgroup$ – Nasser May 3 '20 at 12:26
  • $\begingroup$ Thank so much. I will try it now. $\endgroup$ – Binjiu May 3 '20 at 12:29

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.