Animating the Shapes

Before we finish our first programming session, let’s do something cool. Let’s make all of our shapes spin around like crazy.

In ICE, add the following code after all of the shapes:

 
var​ clock = ​new​ THREE.Clock();
 
 
function​ animate() {
 
requestAnimationFrame(animate);
 
var​ t = clock.getElapsedTime();
 
 
ball.rotation.set(t, 2*t, 0);
 
box.rotation.set(t, 2*t, 0);
 
tube.rotation.set(t, 2*t, 0);
 
ground.rotation.set(t, 2*t, 0);
 
donut.rotation.set(t, 2*t, 0);
 
 
renderer.render(scene, camera);
 
}
 
 
animate();

Don’t worry about what everything means in that code—we’ll look at all of these lines in greater detail later in the book. For now, it’s enough to know that at specific time intervals, we’re changing ...

Get 3D Game Programming for Kids now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.