Playing around with Javascript & 3D: Three.js

Following on my previous post on Node.js, I continued to catch up with what I missed in JavaScript, and I discovered 3D with three.js.
Back in my college days I played with OpenGL in C but as 3D was not a primary focus at the time I never went very far as the scaffolding required to get started was too time consuming.

But with three.js you can prototype amazing animations in just a few lines.

I wrote two samples using this library, best used with Google Chrome:

  1. CrazyBox: this simply shows a box rotating randomly at the center of the space, throwing spheres around. The spheres are moving according to a parabolic movement caused by a constant gravity, with no friction. You can move around the box using the mouse thanks to orbit.js
  2. Rosenbrock: in this one you visualize particles animated following a Particle Swarm Optimization (PSO) searching for the minimum of the Rosenbrock function

Let me know if you need explanations on the parabolic movement or the PSO code.

Enjoy!