July 2018
Beginner to intermediate
374 pages
8h 54m
English
We can give this mini-game a space-age feel with the starry background from Chapter 13, Project: Phases of the Moon. Below the win function definition and the collision event listener, add the following code:
| | function addBackground() { |
| | var cover = new THREE.PointsMaterial({color: 'white', size: 2}); |
| | var shape = new THREE.Geometry(); |
| | |
| | var distance = 500; |
| | for (var i = 0; i < 2000; i++) { |
| | var ra = 2 * Math.PI * Math.random(); |
| | var dec = 2 * Math.PI * Math.random(); |
| | |
| | var point = new THREE.Vector3(); |
| | point.x = distance * Math.cos(dec) * Math.cos(ra); |
| | point.y = distance * Math.sin(dec); |
| | point.z = distance * Math.cos(dec) * Math.sin(ra); |
| | |
| | shape.vertices.push(point); |
| |
Read now
Unlock full access