-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
50 lines (36 loc) · 1.31 KB
/
index.js
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
import * as THREE from 'three';
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
const renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
const figure = createFigure(5);
var angleCamera = 0;
var radiusCamera = 10;
scene.add( figure );
camera.position.z = 5;
camera.position.y = 0;
camera.position.x = 0;
function animate() {
requestAnimationFrame( animate );
camera.position.x = radiusCamera * Math.cos(angleCamera);
camera.position.z = radiusCamera * Math.sin(angleCamera);
angleCamera = angleCamera + 0.8;
camera.lookAt(new THREE.Vector3(0,0,0))
renderer.render( scene, camera );
}
function createFigure(k) {
const material = new THREE.LineBasicMaterial({
color: 0xffffff
});
const points = [];
for (let angle = 0; angle < Math.PI * 2; angle+=0.001) {
let x = 5* 1 * Math.cos(k*angle) * Math.cos(angle);
let y = 5* 1 * Math.cos(k*angle) * Math.sin(angle);
points.push(new THREE.Vector3(x, y, 0));
}
const geometry = new THREE.BufferGeometry().setFromPoints( points );
const line = new THREE.Line( geometry, material );
return line;
}
animate();