Chronology Current Month Current Thread Current Date
[Year List] [Month List (current year)] [Date Index] [Thread Index] [Thread Prev] [Thread Next] [Date Prev] [Date Next]

Re: [Phys-L] Physics "applets" in HTML5/JavaScript



On 03/10/2013 10:02 AM, Daniel V. Schroeder wrote:

A decade ago, dozens--possibly hundreds--of us were writing Java
applets. But support for this environment is disappearing very
quickly, and it never did work on mobile devices.

That's a good point ... and it has spawned an interesting
and informative discussion. Thanks, everybody!

Can anyone out there help me understand why there aren't more
educational physics "applets" written in HTML5/JavaScript?

If you google for "html5 javascript physics" or something similar,
you find almost nothing but pages about game development.

Well, it may not be quite thaaat bad, for a couple of reasons.

1) Not all of us have given up on writing physics applets.
The google query mentioned above will not turn up all the
relevant applets. For example, I recently wrote
http://www.av8n.com/physics/wavefunctions.htm#sec-animation
which uses Javascript. I ported it from an older Java thing.
It uses somewhat-modern Javascript features. As others have
pointed out, the /canvas/ feature is crucial.

Does this applet depend on HTML5? I've never thought about
it. AFAICT it depends on semi-modern Javascript features
but not any bleeding-edge HTML features. In any case,
google has no clue about the HTML5 dependence (if any),
so the aforementioned search will never find this applet.
Maybe it will now, because of this email, but that's a
fluke.

I get 186 hits from the rather restrictive query:
http://www.google.com/search?q=canvas+settimeout+fillstyle+physics+probability+energy
and about 1440 from
http://www.google.com/search?q=canvas+settimeout+fillstyle+physics+energy
and 108 hits from
http://www.google.com/search?q=canvas+settimeout+fillstyle+physics+energy+applet
Those numbers are not huge, but they're not zero, either.

2) IMHO there is some nifty physics in my applet. There
are some lessons about the foundations of what we mean
by probability (as represented by a scatter plot). There
are lessons about what Heisenberg will and will not let
us do, when we start with an energy eigenstate and then
ask questions about the position (which definitely does
not commute with the energy).

Also, I enjoy seeing quantitatively-correct righteous
electron probability distributions, as opposed to the
kooky "artist's impressions" that you all-too-often
see in the literature.

3) I wouldn't be too disdainful of the game development
systems. The term "physics engine" is used in the game
industry for a reason. Guess how I know. The point is,
games need to model the physics, and the better games do
a better job on the physics.

http://en.wikipedia.org/wiki/Physics_engine

Seriously, rather than writing a physics engine from
scratch for research and/or educational purposes, I
would strongly recommend you at least /consider/
the idea of co-opting an open-source game platform.
I'm not saying it will be exactly what you need,
but there should be something like 80% commonality.
That saves you a tremendous amount of work ... and
you get a better result in the end, including probably
a better user interface than you ever dreamed of doing
by yourself.

I am quite aware that it is more /fun/ to write your own
code from scratch, but if you care about productivity,
efficiency, and the quality of the final product, you
should seriously consider /not/ starting from scratch.

Even if you wind up deciding that the other guy's physics
engine is not good enough and you absolutely have to
write your own from scratch, you will be better off
because you will be smarter from having spent some
time wallowing in the other guy's code.

The best case is that you do such a good job that the
game guys adopt your notion of what the physics engine
should be like. They help you finish it, extend it,
and support it.

The worst case is that they aren't interested, and you
wind up forking the code. That's sad, but it's still
better than starting from scratch.

FWIW I know of a flight simulator program that has
five different physics engines. They're sufficiently
modular that you can pick the one you want and plug
it in.

==============

It's kinda sad what happened to Java. It's not every
day you see something go from "favored" to "disfavored"
quite so quickly.

If they hadn't screwed up the security, it would have
been better than Javascript for any and all serious
applications. Strong typing leads to better code,
and feature-rich /libraries/ lead to much much better
code.

When I ported the atomic scatter-plot applet, I spent
a couple of hours googling for a binary search utility,
discovering that the one I downloaded was no good, debugging
it, and eventually almost completely rewriting it. In
Java or any other well-behaved language, I would have
just called a library routine and would have had every
confidence that it would be reliable and efficient and
well-documented. The thing is only ten lines long, but
that is ten lines of code that folks shouldn't have to
write again and again.