|
50 | 50 | <script src="js/renderers/CanvasRenderer.js"></script> |
51 | 51 |
|
52 | 52 | <script src="js/Detector.js"></script> |
53 | | - <script src="js/libs/stats.min.js"></script> |
54 | 53 | <script src="js/geometries/hilbert3D.js"></script> |
| 54 | + <script src="js/geometries/hilbert2D.js"></script> |
55 | 55 |
|
56 | 56 | <script> |
57 | 57 |
|
58 | 58 | if ( ! Detector.webgl ) Detector.addGetWebGLMessage(); |
59 | 59 |
|
| 60 | + var mouseX = 0, mouseY = 0; |
60 | 61 |
|
61 | | - var mouseX = 0, mouseY = 0, |
| 62 | + var windowHalfX = window.innerWidth / 2; |
| 63 | + var windowHalfY = window.innerHeight / 2; |
62 | 64 |
|
63 | | - windowHalfX = window.innerWidth / 2, |
64 | | - windowHalfY = window.innerHeight / 2, |
65 | | - |
66 | | - camera, scene, renderer, material; |
| 65 | + var camera, scene, renderer; |
67 | 66 |
|
68 | 67 | init(); |
69 | 68 | animate(); |
70 | 69 |
|
71 | 70 | function init() { |
72 | 71 |
|
73 | | - var i, container; |
74 | | - |
75 | | - container = document.createElement( 'div' ); |
76 | | - document.body.appendChild( container ); |
77 | | - |
78 | 72 | camera = new THREE.PerspectiveCamera( 33, window.innerWidth / window.innerHeight, 1, 10000 ); |
79 | | - camera.position.z = 700; |
| 73 | + camera.position.z = 1000; |
80 | 74 |
|
81 | 75 | scene = new THREE.Scene(); |
82 | 76 |
|
83 | 77 | renderer = new THREE.CanvasRenderer(); |
84 | 78 | renderer.setPixelRatio( window.devicePixelRatio ); |
85 | 79 | renderer.setSize( window.innerWidth, window.innerHeight ); |
86 | | - container.appendChild( renderer.domElement ); |
| 80 | + document.body.appendChild( renderer.domElement ); |
| 81 | + |
| 82 | + // 2d lines |
| 83 | + |
| 84 | + var geometry2 = new THREE.Geometry(), |
| 85 | + points = hilbert2D( new THREE.Vector3( 0, 0, 0 ), 400, 4 ), |
| 86 | + colors2 = []; |
| 87 | + |
| 88 | + for ( i = 0; i < points.length; i ++ ) { |
| 89 | + |
| 90 | + geometry2.vertices.push( points[ i ] ); |
| 91 | + |
| 92 | + colors2[ i ] = new THREE.Color( 0xffffff ); |
| 93 | + colors2[ i ].setHSL( i / points.length, 1, 0.5 ); |
| 94 | + |
| 95 | + } |
| 96 | + |
| 97 | + geometry2.colors = colors2; |
| 98 | + |
| 99 | + // 3d lines |
87 | 100 |
|
88 | 101 | var geometry3 = new THREE.Geometry(), |
89 | | - points = hilbert3D( new THREE.Vector3( 0,0,0 ), 200.0, 2, 0, 1, 2, 3, 4, 5, 6, 7 ), |
| 102 | + points = hilbert3D( new THREE.Vector3( 0, 0, 0 ), 200, 2, 0, 1, 2, 3, 4, 5, 6, 7 ), |
90 | 103 | colors3 = []; |
91 | 104 |
|
92 | 105 | for ( i = 0; i < points.length; i ++ ) { |
93 | 106 |
|
94 | 107 | geometry3.vertices.push( points[ i ] ); |
95 | 108 |
|
96 | 109 | colors3[ i ] = new THREE.Color( 0xffffff ); |
97 | | - colors3[ i ].setHSL( i / points.length, 1.0, 0.5 ); |
| 110 | + colors3[ i ].setHSL( i / points.length, 1, 0.5 ); |
98 | 111 |
|
99 | 112 | } |
100 | 113 |
|
101 | 114 | geometry3.colors = colors3; |
102 | 115 |
|
103 | 116 | // lines |
104 | 117 |
|
105 | | - material = new THREE.LineBasicMaterial( { color: 0xffffff, opacity: 1, linewidth: 3, vertexColors: THREE.VertexColors } ); |
106 | | - |
107 | | - var line, p, scale = 0.3, d = 225; |
108 | | - |
109 | | - line = new THREE.Line(geometry3, material ); |
110 | | - line.scale.x = line.scale.y = line.scale.z = scale*1.5; |
111 | | - line.position.x = 0; |
112 | | - line.position.y = 0; |
113 | | - line.position.z = 0; |
114 | | - scene.add( line ); |
| 118 | + var material = new THREE.LineBasicMaterial( { color: 0xffffff, linewidth: 3, vertexColors: THREE.VertexColors } ); |
115 | 119 |
|
116 | | - // |
| 120 | + var line3d = new THREE.Line( geometry3, material ); |
| 121 | + line3d.scale.set( 0.4, 0.4, 0.4 ); |
| 122 | + line3d.position.set( 200, 0, 0 ); |
| 123 | + scene.add( line3d ); |
117 | 124 |
|
118 | | - stats = new Stats(); |
119 | | - //container.appendChild( stats.dom ); |
| 125 | + var line2d = new THREE.Line( geometry2, material ); |
| 126 | + line2d.scale.copy( line3d.scale ); |
| 127 | + line2d.position.set( - 200, 0, 0 ); |
| 128 | + scene.add( line2d ); |
120 | 129 |
|
121 | 130 | // |
122 | 131 |
|
|
183 | 192 | requestAnimationFrame( animate ); |
184 | 193 | render(); |
185 | 194 |
|
186 | | - stats.update(); |
187 | | - |
188 | 195 | } |
189 | 196 |
|
190 | 197 | function render() { |
191 | 198 |
|
192 | | - camera.position.x += ( mouseX - camera.position.x ) * .05; |
193 | | - camera.position.y += ( - mouseY + 200 - camera.position.y ) * .05; |
| 199 | + camera.position.x += ( mouseX - camera.position.x ) * 0.05; |
| 200 | + camera.position.y += ( - mouseY + 200 - camera.position.y ) * 0.05; |
194 | 201 |
|
195 | 202 | camera.lookAt( scene.position ); |
196 | 203 |
|
|
199 | 206 | for ( var i = 0; i < scene.children.length; i ++ ) { |
200 | 207 |
|
201 | 208 | var object = scene.children[ i ]; |
202 | | - if ( object instanceof THREE.Line ) object.rotation.y = time * ( i % 2 ? 1 : -1 ); |
| 209 | + |
| 210 | + if ( object.isLine ) { |
| 211 | + |
| 212 | + object.rotation.y = time * ( i % 2 ? 1 : -1 ); |
| 213 | + |
| 214 | + } |
203 | 215 |
|
204 | 216 | } |
205 | 217 |
|
206 | | - renderer.render(scene, camera ); |
| 218 | + renderer.render( scene, camera ); |
207 | 219 |
|
208 | 220 | } |
209 | 221 |
|
|
0 commit comments