Traer physics library for Processing.js (download)

1204 views
Skip to first unread message

Mike Niemi

unread,
Dec 16, 2010, 10:10:26 AM12/16/10
to Processing.js
I ported Jeffrey Traer's physics library to Processing.js. Here are
some samples:
http://svbreakaway.info/tp-downloads.php#samples
and some notes regarding the port:
http://svbreakaway.info/tp.php#tpjs

The Traer physics library code is included as traer3.pde in each of
the sample downloads.

Mike

Jeremy Arca

unread,
Dec 16, 2010, 2:06:16 PM12/16/10
to proces...@googlegroups.com
you're awesome for doing this! ilove this lib.


--
You received this message because you are subscribed to the Google Groups "Processing.js" group.
To post to this group, send email to proces...@googlegroups.com.
To unsubscribe from this group, send email to processingjs...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/processingjs?hl=en.


Will Farrell

unread,
Dec 16, 2010, 2:25:18 PM12/16/10
to proces...@googlegroups.com
Well done Sir! The lack of traer physics in processingjs made me sad, but you've just made me a happy coder.

There seems to be a huge performance difference between Firefox and Chrome. For me it runs super fast in chrome (rivaling the speed of processing java applets) but in Firefox it's unusably slow.  The performance difference seems to be several orders magnitudes off, is it just me and do you know why this might be?

Thanks so much, I will definitely make very heavy use of this.

On Thu, Dec 16, 2010 at 7:10 AM, Mike Niemi <svbre...@gmail.com> wrote:

Anna Sobiepanek

unread,
Dec 16, 2010, 4:30:20 PM12/16/10
to proces...@googlegroups.com
hi,

It does appear a little slower in Firefox. However, if you download the Firefox beta there is a significant improvement.

Anna

Kyle Phillips

unread,
Dec 16, 2010, 4:36:03 PM12/16/10
to proces...@googlegroups.com
This is really great! thanks for this excellent contribution!

@Will I've noticed that with most canvas sketches. I don't think its based on the Traer lib. I think Firefox's JavaScript engine (TraceMonkey?) is just lacking that much from Chrome's. Even in Firefox 4 beta, still worse :( It might not be the case though on Windows, as FF4 beta introduced hardware acceleration for Windows.


-Kyle Phillips

Mike Niemi

unread,
Dec 17, 2010, 5:58:12 AM12/17/10
to Processing.js
Thank you all for the kind words.

Will and all,
I just added an option to the pendulum sample to report fps. There is
also a button (initially labeled "Undefined") next to the fps that
will set frameRate(). The sample didn't (and still doesn't) set
frameRate() when it starts. Clicking on the button once (to
"Limited") results in a call to frameRate(60). Clicking on it a
second time (to "Unlimited") results in a call to frameRate(9999).
For the Unlimited case, I'm seeing
IDE: 460 fps
Opera: 218 fps
Chrome: 201 fps
Safari: 99 fps
Firefox: 47 fps :-(
These were on Mac OS-X on a 13" MBP. I'll do some runs on Windows (I
only have Vista though) including IE9 beta. And I'll try the FF4
beta. The specific versions I'm using are listed here:
http://svbreakaway.info/tp.php#dec17

Mike

Carl Pearson

unread,
Feb 9, 2011, 11:27:39 AM2/9/11
to proces...@googlegroups.com
I pointed out some errors in the Euler integrators to Mike, which he said he would incorporate in his download (note: these errors still exist in the original Processing library; I pointed them out to Jeff awhile ago).

I've also attached an update of the traer3.pde that refactors to use the native PVector instead of Vector3D (though the js version does *not* correctly implement everything that it claims to in the docs), and includes some new convenient forces (UniversalAttraction, Pulse) which I demonstrate in the dynamics.pde (which is basically Mike's original pendulums.pde rewritten to take advantage of those).

Enjoy!

ps - if it weren't obvious, the pde's have been attached as txt files.
dynamics.txt
traer3.txt

flyingoctopus

unread,
Mar 23, 2011, 5:22:02 PM3/23/11
to Processing.js
Has there been any tests with using ParticleSystem? I'm getting the
error:
"
Unable to execute pjs sketch: ReferenceError: RUNGE_KUTTA is not
defined
"

when executing:
"
physics = new ParticleSystem(grav,drag);
physics.setIntegrator( ParticleSystem.MODIFIED_EULER );
"

I'm baffled, as I see RUNGE_KUTTA defined in traer3a.pde
>  dynamics.txt
> 6KViewDownload
>
>  traer3.txt
> 26KViewDownload

Mike Niemi

unread,
Mar 23, 2011, 11:58:10 PM3/23/11
to Processing.js
That does look like a weird one. On recreating the problem, I see
that error message occurring with the Processing-1.1.0.js but not with
Processing-1.0.0.js.

What seems to be working for me for MODIFIED_EULER is:
(1) use Processing-1.0.0.js and
(2) replace ModifiedEulerIntegrator in traer3a with the following
version:

===========================================================
// This is a workaround version of the code based on traer3, for use
in traer3a
// to avoid a hang at the start of the animation
public class ModifiedEulerIntegrator implements Integrator
{
ParticleSystem s;
public ModifiedEulerIntegrator( ParticleSystem s ) { this.s = s; }
public void step( float t )
{
s.clearForces();
s.applyForces();

float halftt = 0.5f*t*t;

for ( int i = 0; i < s.numberOfParticles(); i++ )
{
Particle p = s.getParticle( i );
if ( p.isFree() )
{
float ax = p.force.x/p.mass();
float ay = p.force.y/p.mass();
float az = p.force.z/p.mass();

p.position.add( p.velocity.x*t, p.velocity.y*t, p.velocity.z*t );
p.position.add( ax*halftt, ay*halftt, az*halftt );
p.velocity.add( ax*t, ay*t, az*t );
}
}
}
} // ModifiedEulerIntegrator
===========================================================

As a workaround for now. It appears to work for me on the dynamics
sample program with:

physics = new ParticleSystem( 1, 0.3 ); // bumped the drag up
from 0.05
physics.setIntegrator( ParticleSystem.MODIFIED_EULER );

I'll try to sort out the problems.

Mike

Mike Niemi

unread,
Mar 24, 2011, 10:39:06 AM3/24/11
to Processing.js
There appear to have been a couple problems.

First, as you note, RUNGE_KUTTA was not being seen by the code inside
the switch statement. Changing the switch statement to an if-then-
else avoids the problem. This problem appears to have been introduced
with Processing-1.1.0.js and only occurs when using the ModifiedEuler.

Second, the code in ModifiedEulerIntegrator was using PVector APIs
which appear to work in the IDE but not in pjs. I couldn't find any
documentation for those APIs being used. I changed the code to use
the documented API and it seems to be working now in both the IDE and
pjs.

Here is the modified library (traer3a_01.pde):
http://svbreakaway.info/definitions/tp-downloads/dynamics_01/traer3a_01.pde
and I've updated my dynamics sample download (http://svbreakaway.info/
tp-downloads.php#samples) to include the changed library.

Let me know if you have any problems.

Mike

On Mar 23, 5:22 pm, flyingoctopus <vinc...@vanhaaff.com> wrote:

Anna Sobiepanek

unread,
Mar 24, 2011, 10:49:08 AM3/24/11
to proces...@googlegroups.com
Hey Mike,

You said "This problem appears to have been introduced with


Processing-1.1.0.js and only occurs when using the ModifiedEuler."

Does this need to be fixed in pjs? Let me know if you can nail down
the problem so that pjs can be fixed.

Anna

Mike Niemi

unread,
Mar 24, 2011, 2:07:56 PM3/24/11
to Processing.js
Thanks Anna,
You probably saw it already, but I just opened a ticket (#1180) with a
testcase that I think should recreate the problem. Let me know in
case there are any questions. It seemed pretty easy to reproduce (but
I'll add a little to the ticket about my configuration just in case).
Mike

On Mar 24, 10:49 am, Anna Sobiepanek <anna.sobiepa...@gmail.com>
wrote:
> Hey Mike,
>
> You said "This problem appears to have been introduced with
> Processing-1.1.0.js and only occurs when using the ModifiedEuler."
> Does this need to be fixed in pjs? Let me know if you can nail down
> the problem so that pjs can be fixed.
>
> Anna
>
> On Thu, Mar 24, 2011 at 10:39 AM, Mike Niemi <svbreaka...@gmail.com> wrote:
> > There appear to have been a couple problems.
>
> > First, as you note, RUNGE_KUTTA was not being seen by the code inside
> > the switch statement.  Changing the switch statement to an if-then-
> > else avoids the problem.  This problem appears to have been introduced
> > with Processing-1.1.0.js and only occurs when using the ModifiedEuler.
>
> > Second, the code in ModifiedEulerIntegrator was using PVector APIs
> > which appear to work in the IDE but not in pjs.  I couldn't find any
> > documentation for those APIs being used.  I changed the code to use
> > the documented API and it seems to be working now in both the IDE and
> > pjs.
>
> > Here is the modified library (traer3a_01.pde):
> >    http://svbreakaway.info/definitions/tp-downloads/dynamics_01/traer3a_...

David Faveris

unread,
Feb 29, 2016, 8:58:14 AM2/29/16
to Processing.js
Hi Mike here you can find the way I have used your méga hyper cool traer.pde  : http://smag0.meteor.com

the goal is to share ideas and project, visualize them and collaborate, in a simple way... the result can be seen as a #RDF graphe.


@DFaveris
Reply all
Reply to author
Forward
0 new messages