2
$\begingroup$

Hakim El Hattab's Sphere, consists of only a handful of lines of Javascript, and would probably be even terser if written in Mathematica.

How difficult would it be to "transcode" Mathematica to JS?

Further, what is necessary to write the Mathematica code on a desktop and program it to negotiate with ssh or sftp to actually upload the scripts to a web server?

Sorry if being a bit vague here, just getting into the web services aspect.

$\endgroup$
5
  • $\begingroup$ Sorry, I don't quite understand what is your question. Is it about that sphere? About translating Mma into JS? About transferring files programatically? $\endgroup$ Commented Jul 21, 2012 at 20:23
  • $\begingroup$ All the above. Of those, translating JS --> MMA is easy except that JS is better suited for animation and event-handling. Suppose that the mathematical part of the code is written in MMA. What's the quickest way to render it in a web browser? $\endgroup$ Commented Jul 21, 2012 at 20:38
  • 2
    $\begingroup$ If you've got code that runs well in Javascript on your browser, it would be crazy to port it to Mathematica and then try to run it in a browser using the CDF plugin - JS is ubiquitous and lightweight, whereas CDF is rare and heavyweight... If you did try to program this particular example in MMA, you'd need to emulate the proper blend mode using raster images, see this question $\endgroup$
    – Jens
    Commented Jul 21, 2012 at 21:43
  • $\begingroup$ I wouldn't want to develop the "magic" part of the code in JS- that's the point of my question. How to carve this problem at the joints: coding the core component MMA, and then transcoding it in JS? Possible? $\endgroup$ Commented Jul 22, 2012 at 1:49
  • $\begingroup$ WARNING Linking to that "sphere" page produced numerous "unresponsive script" messages. Eventually I had to shut down FireFox with extreme prejudice. $\endgroup$
    – whuber
    Commented Jul 23, 2012 at 13:12

1 Answer 1

6
$\begingroup$

If you really want to go this way then the following is a starting point; however in the comments there are good points why this is not the best solution.

r = Compile[{{w, _Real}, {h, _Real}, {time, _Real}, {i, _Integer}}, 
            (0.4 (w + h)) Cos[(time + i) (0.05 + Sin[time*0.00002]/Pi 0.2)]/Pi]

w = 1.;
h = 1.;
Manipulate[Graphics[
  Table[Point[{Sin[i]*r[w, h, time, i] + (w/2), Cos[i]*r[w, h, time, i] + (h/2)}],
        {i, 1, 1000}]], {time, 0, 1000, 0.05}]

hakim

$\endgroup$
2
  • $\begingroup$ +1 and accepted as per my original Q. However, as Jens commented, to get this to run in a browser as Mathematica code would be unwieldy. So how to transcode the algorithmic portion of the Sphere MMA --> JS ? Using JLink? $\endgroup$ Commented Jul 22, 2012 at 16:55
  • $\begingroup$ @alancalvitti I personally know very little about JS - sorry can't help. $\endgroup$ Commented Jul 22, 2012 at 19:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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