-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello_world.js
More file actions
88 lines (54 loc) · 2.16 KB
/
hello_world.js
File metadata and controls
88 lines (54 loc) · 2.16 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
// JavaScript Document
var camera, scene, renderer;
var geometry, material;
var mesh = new Array();
var numcubes = 7;
var cubesize = 200;
init();
animate();
function init() {
//Camera
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 1000000 );
camera.position.z = 1000;
camera2 = new THREE.OrthographicCamera( window.innerWidth / - 2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / - 2, 1, 10000 );
camera2.position.z = 1000;
//
scene = new THREE.Scene();
//
geometry = new THREE.CubeGeometry( cubesize, cubesize, cubesize );
material = new THREE.MeshBasicMaterial( { color: 0xff0000, wireframe: true } );
for( var i=0 ; i<numcubes ; i++ ){
mesh[i] = new THREE.Mesh( geometry, material );
scene.add( mesh[i] );
}
//
renderer = new THREE.WebGLRenderer();
//renderer = new THREE.CanvasRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
}
var move = 0;
function animate() {
// note: three.js includes requestAnimationFrame shim
requestAnimationFrame( animate );
renderer.autoClear = false;
//mesh.rotation.x += 0.01;
//mesh.rotation.y += 0.02;
for(var i=0 ; i<numcubes ; i++ ){
/*
mesh[i].rotation.z = (2*Math.PI*((i)/numcubes)+move)%(2*Math.PI);
mesh[i].position.x = 500*Math.sin(2*Math.PI*(i/numcubes));
mesh[i].position.y = 500*Math.cos(2*Math.PI*(i/numcubes));
*/
mesh[i].rotation.z = ((2*Math.PI/numcubes)*(numcubes-i))-move;
mesh[i].position.x = (((cubesize/2)/Math.tan((2*Math.PI)/numcubes/2))+(cubesize/2))*Math.sin(2*Math.PI*(i/numcubes)+move);
mesh[i].position.y = (((cubesize/2)/Math.tan((2*Math.PI)/numcubes/2))+(cubesize/2))*Math.cos(2*Math.PI*(i/numcubes)+move);
}
move+=0.01;
//mesh.scale = 0.5;
//mesh.translateX(100+Math.random()*100-50);
// mesh.translateY(100+Math.random()*100-50);
//mesh.position.x+=10;
renderer.render( scene, camera );
//renderer.render( scene, camera2 );
}