Bonus #1: Random Colors

Purple is a great color. But if you prefer more variety, it would be nice to randomly choose color. The problem is that the colors we’ve seen so far have been named colors, like blue.

​ ​var​ shape = ​new​ THREE.SphereGeometry(50);
»​var​ cover = ​new​ THREE.MeshBasicMaterial({color: ​'blue'​});
​ ​var​ planet = ​new​ THREE.Mesh(shape, cover);
​ planet.position.​set​(-500,0,0);
​ scene.add(planet);

Named colors like blue, yellow, and purple are hard to randomize. Happily, you can make colors other ways in programming. One of the most common ways uses a number between 0 and 1 to specify how much red, green, and blue go into a color.

Here are some common colors in red, green, blue ...

Get 3D Game Programming for Kids, 2nd Edition 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.