JSDM

HTML

 
1

CSS

xxxxxxxxxx
2
 
1
* {margin: 0; padding: 0;}
2
canvas {display: block;}
? ?
? ?
必须是有效的URL
+ 添加另一个资源

JS

xxxxxxxxxx
73
 
1
var scene, width, height, camera, cubeCamera, renderer, toruses, box;
2
3
init();
4
function init() {
5
  var boxGeometry, boxMaterial, light;
6
7
  scene = new THREE.Scene();
8
  width = window.innerWidth;
9
  height = window.innerHeight;
10
  camera = new THREE.PerspectiveCamera(45, width / height, 0.1, 1000);
11
  cubeCamera = new THREE.CubeCamera(1, 1000, 20);
12
  renderer = new THREE.WebGLRenderer();
13
  toruses = [];
14
15
  boxGeometry = new THREE.BoxGeometry(2, 2, 2);
16
  boxMaterial = new THREE.MeshBasicMaterial({ 
17
    envMap: cubeCamera.renderTarget,
18
    reflectivity: 0.8,
19
    color: 0xFFFFFF
20
  });
21
  box = new THREE.Mesh(boxGeometry, boxMaterial);
22
  box.position.set(0, 0, 0);
23
  scene.add(box);
24
25
  renderer.setSize(width, height);
26
  renderer.setClearColor(0x17293a);
27
28
  cubeCamera.position.set(0, 0, 0);
29
  scene.add(cubeCamera);
30
  camera.position.set(0, -50, 0);
31
  camera.lookAt(scene.position);
32
33
  generateToruses(200, 10);
34
35
  document.body.appendChild(renderer.domElement);
36
37
  drawFrame();
38
}
39
40
function generateToruses(num, step) {
41
  var torusGeometry, torusMaterial, torus,
42
      radius, colors;
43
44
  colors = ['#f1c40f', '#f39c12', '#e67e22', '#d35400', '#e74c3c', '#c0392b'];
45
46
  for (var i = -num; i < num; i += step) {
47
    radius = 4 + Math.random() * 8;
48
    torusGeometry = new THREE.TorusGeometry(radius, 1, 8, 30, Math.PI * 2);
49
    torusMaterial = new THREE.MeshBasicMaterial({color: colors[Math.floor(Math.random() * colors.length)]});
50
    torus = new THREE.Mesh(torusGeometry, torusMaterial);
51
    torus.position.set(0, 0, i);
52
    torus.rotation.set(-0.1 + Math.random() * 0.2, -0.3 + Math.random() * 0.6, 0);
53
    scene.add(torus);
54
    toruses.push(torus);
55
  }
56
}
57
58
function drawFrame() {
59
  var speed = 0.05;
60
  window.requestAnimationFrame(drawFrame);
61
  renderer.render(scene, camera);
62
  box.rotation.z += speed;
63
  box.rotation.y += speed;
64
  toruses.forEach(moveTorus);
65
  cubeCamera.visible = false;
66
  cubeCamera.updateCubeMap( renderer, scene );
67
  cubeCamera.visible = true;
68
}
69
70
function moveTorus(torus) {
71
  torus.position.z += 0.6;
72
  if (torus.position.z >= 200) torus.position.z = -200;
73
}
必须是有效的URL
+ 添加另一个资源
Close

文件管理 点击文件查看URL

图片

  1. 暂无文件

CSS

  1. 暂无文件

JavaScript

  1. 暂无文件

其他

  1. 暂无文件
拖动文件到上面的区域或者:
加载中 ..................