index.html 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset=utf-8>
  5. <title>Ring test</title>
  6. <style>
  7. body {
  8. color: #999999;
  9. background: #555555;
  10. margin: 0;
  11. }
  12. canvas {
  13. width: 100%;
  14. height: 100%;
  15. }
  16. </style>
  17. </head>
  18. <body>
  19. <script src=js/three.js></script>
  20. <script>
  21. // Set up WebGL canvas.
  22. var width = window.innerWidth;
  23. var height = window.innerHeight;
  24. var camera = new THREE.PerspectiveCamera(75, width/height, 0.1, 1000);
  25. var renderer = new THREE.WebGLRenderer();
  26. renderer.setSize(width, height);
  27. document.body.appendChild(renderer.domElement);
  28. var scene = new THREE.Scene();
  29. var geometry = new THREE.BoxGeometry(0.4, 0.9, 0.1);
  30. var material = new THREE.MeshStandardMaterial( { color: 0x99aaff, } );
  31. var box = new THREE.Mesh(geometry, material);
  32. scene.add(box);
  33. // Put the floor at -1.0 m so the origin is in front of us.
  34. camera.position.z = 2.0;
  35. camera.position.y = 0.6;
  36. camera.lookAt(new THREE.Vector3(0, 0, 0));
  37. var light = new THREE.PointLight(0xffffff);
  38. light.position.x = 10;
  39. light.position.y = 50;
  40. light.position.z = 100;
  41. scene.add(light);
  42. function origin_ring(radius = 0.60) {
  43. let points = 128;
  44. let curve = new THREE.EllipseCurve(0, 0, radius , radius, 0, 2.0*Math.PI,
  45. false, Math.PI/2);
  46. let path = new THREE.Path( curve.getPoints(points) );
  47. let geometry = path.createPointsGeometry(points);
  48. let material = new THREE.LineBasicMaterial( { color: 0x999999, } );
  49. let circle = new THREE.Line(geometry, material);
  50. return circle;
  51. }
  52. scene.add(origin_ring(1.0));
  53. function render() {
  54. requestAnimationFrame(render);
  55. renderer.render(scene, camera);
  56. box.rotation.x += 0.01;
  57. box.rotation.y += 0.01;
  58. }
  59. render();
  60. </script>
  61. </body>
  62. </html>