# Hakim's Sphere in Mathematica?

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.

-
Sorry, I don't quite understand what is your question. Is it about that sphere? About translating Mma into JS? About transferring files programatically? –  belisarius Jul 21 '12 at 20:23
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? –  alancalvitti Jul 21 '12 at 20:38
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 –  Jens Jul 21 '12 at 21:43
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? –  alancalvitti Jul 22 '12 at 1:49
WARNING Linking to that "sphere" page produced numerous "unresponsive script" messages. Eventually I had to shut down FireFox with extreme prejudice. –  whuber Jul 23 '12 at 13:12

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}]


-
+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? –  alancalvitti Jul 22 '12 at 16:55
@alancalvitti I personally know very little about JS - sorry can't help. –  b.gatessucks Jul 22 '12 at 19:15