Interactive three.js demo

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.

Capture

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:

Capture

Three.js scene initialization:

Capture

Addition of objects to the scene:

Capture

I used render() as an update loop.

update():
– Watches for key presses.

Capture
– Increments along x and y using a capped, decaying delta for each.

Capture

Capture
– Bounces off of imaginary walls.

Capture
– Uses the camera’s lookat() function to loosely follow the sliding cube.

Capture

There’s also a little snippet to handle window resizing.

Capture

Leave a Reply

Your email address will not be published. Required fields are marked *