This was a soft introduction to three.js.
Three.js is a low-overhead wrapper for WebGL in HTML5.
Demo Here!
Use the arrow keys to push a little cube around on a bounded surface.
The source consists of the following bits, as well as a few others you can see in the source…
Event listeners for the arrow keys:
Three.js scene initialization:
Addition of objects to the scene:
I used render() as an update loop.
update():
– Watches for key presses.
– Increments along x and y using a capped, decaying delta for each.
– Bounces off of imaginary walls.
– Uses the camera’s lookat() function to loosely follow the sliding cube.
There’s also a little snippet to handle window resizing.