-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
96 lines (69 loc) · 2.29 KB
/
index.html
File metadata and controls
96 lines (69 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!doctype html>
<html>
<head>
<title>Three.js tutorial</title>
</head>
<body>
<script src="js/three.min.js"></script>
<script src="js/OrbitControls.js"></script>
<script>
// Set up the scene, camera, and renderer as global variables.
var scene, camera, renderer;
var atoms = [];
var numatoms = 10;
init();
animate();
// Sets up the scene.
function init() {
// Create the scene and set the scene size.
scene = new THREE.Scene();
var WIDTH = window.innerWidth,
HEIGHT = window.innerHeight;
// Create a renderer and add it to the DOM.
renderer = new THREE.WebGLRenderer({antialias:true});
renderer.setSize(WIDTH, HEIGHT);
document.body.appendChild(renderer.domElement);
// Create a camera, zoom it out from the model a bit, and add it to the scene.
camera = new THREE.PerspectiveCamera(45, WIDTH / HEIGHT, 0.1, 20000);
camera.position.set(0,10,0);
scene.add(camera);
// Set the background color of the scene.
renderer.setClearColorHex(0xFFFFFF, 1);
// Create a light, set its position, and add it to the scene.
var light = new THREE.PointLight(0xffffff);
light.position.set(-100,200,100);
scene.add(light);
// Add geometry, define sphere object
var sphereMesh = new THREE.SphereGeometry(1,16,16);
var sphereMaterial = new THREE.MeshLambertMaterial({color: 0xCC0000}); // Red sphere
for (i = 1; i <= numatoms; i++) {
var tempSphere = new THREE.Mesh(sphereMesh, sphereMaterial);
tempSphere.name = "sphere" + i;
tempSphere.position.z = -10 + 2*i;
scene.add(tempSphere);
atoms.push(tempSphere);
}
var cube = new THREE.BoxHelper();
cube.material.color.setRGB( 1, 0, 0 );
cube.scale.set( 10, 10, 10 );
scene.add( cube );
// Add OrbitControls so that we can pan around with the mouse.
controls = new THREE.OrbitControls(camera, renderer.domElement);
}
// Renders the scene and updates the render as needed.
function animate() {
// Read more about requestAnimationFrame at http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
requestAnimationFrame(animate);
var sphere = scene.getObjectByName( "sphere2", true );
sphere.position.x -= 0.1;
atoms[4].position.x += 0.01;
if (sphere.position.x < -10) {
sphere.position.x += 20;
}
// Render the scene.
renderer.render(scene, camera);
controls.update();
}
</script>
</body>
</html>