Skip to content

Commit 77d7a99

Browse files
committed
Somehow the trails example got deleted... ?
1 parent 44730f9 commit 77d7a99

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed

examples/webgl_trails.html

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<title>three.js webgl - trails</title>
5+
<meta charset="utf-8">
6+
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
7+
<style>
8+
body {
9+
background:#000;
10+
padding:0;
11+
margin:0;
12+
font-weight: bold;
13+
overflow:hidden;
14+
}
15+
</style>
16+
</head>
17+
<body>
18+
19+
<script src="../build/Three.js"></script>
20+
21+
<script src="js/RequestAnimationFrame.js"></script>
22+
<script src="js/Stats.js"></script>
23+
24+
<script>
25+
26+
var container, stats;
27+
28+
var camera, scene, renderer;
29+
30+
var mesh, zmesh, lightMesh, geometry;
31+
32+
var mouseX = 0, mouseY = 0;
33+
34+
var windowHalfX = window.innerWidth / 2;
35+
var windowHalfY = window.innerHeight / 2;
36+
37+
document.addEventListener( 'mousemove', onDocumentMouseMove, false );
38+
39+
init();
40+
animate();
41+
42+
43+
function init() {
44+
45+
container = document.createElement( 'div' );
46+
document.body.appendChild( container );
47+
48+
camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 10000 );
49+
camera.position.x = 100000;
50+
camera.position.z = 3200;
51+
52+
scene = new THREE.Scene();
53+
54+
var colors = [ 0x000000, 0xff0080, 0x8000ff, 0xffffff ];
55+
var geometry = new THREE.Geometry();
56+
57+
for ( var i = 0; i < 2000; i ++ ) {
58+
59+
var vertex = new THREE.Vertex();
60+
vertex.position.x = Math.random() * 4000 - 2000;
61+
vertex.position.y = Math.random() * 4000 - 2000;
62+
vertex.position.z = Math.random() * 4000 - 2000;
63+
geometry.vertices.push( vertex );
64+
65+
geometry.colors.push( new THREE.Color( colors[ Math.floor( Math.random() * colors.length ) ] ) );
66+
67+
}
68+
69+
var material = new THREE.ParticleBasicMaterial( { size: 1, vertexColors: THREE. VertexColors, depthTest: false, opacity: 0.5, sizeAttenuation: false } );
70+
71+
var mesh = new THREE.ParticleSystem( geometry, material );
72+
scene.add( mesh );
73+
74+
renderer = new THREE.WebGLRenderer( { preserveDrawingBuffer: true } );
75+
renderer.setSize( window.innerWidth, window.innerHeight );
76+
renderer.sortObjects = false;
77+
renderer.autoClearColor = false;
78+
container.appendChild( renderer.domElement );
79+
80+
stats = new Stats();
81+
stats.domElement.style.position = 'absolute';
82+
stats.domElement.style.top = '0px';
83+
stats.domElement.style.zIndex = 100;
84+
container.appendChild( stats.domElement );
85+
86+
}
87+
88+
function onDocumentMouseMove(event) {
89+
90+
mouseX = ( event.clientX - windowHalfX ) * 10;
91+
mouseY = ( event.clientY - windowHalfY ) * 10;
92+
93+
}
94+
95+
//
96+
97+
function animate() {
98+
99+
requestAnimationFrame( animate );
100+
101+
render();
102+
stats.update();
103+
104+
}
105+
106+
function render() {
107+
108+
camera.position.x += ( mouseX - camera.position.x ) * .05;
109+
camera.position.y += ( - mouseY - camera.position.y ) * .05;
110+
111+
camera.lookAt( scene.position );
112+
113+
renderer.render( scene, camera );
114+
115+
}
116+
117+
</script>
118+
119+
</body>
120+
</html>

0 commit comments

Comments
 (0)