canvas_ascii_effect.html 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js - ASCII Effect</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. font-family: Monospace;
  10. background-color: #f0f0f0;
  11. margin: 0px;
  12. overflow: hidden;
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <script src="../build/Three.js"></script>
  18. <script src="js/effects/AsciiEffect.js"></script>
  19. <script src="js/Stats.js"></script>
  20. <script>
  21. var container, stats;
  22. var camera, controls, scene, renderer;
  23. var sphere, plane;
  24. var start = Date.now();
  25. init();
  26. animate();
  27. function init() {
  28. container = document.createElement( 'div' );
  29. document.body.appendChild( container );
  30. var info = document.createElement( 'div' );
  31. info.style.position = 'absolute';
  32. info.style.top = '10px';
  33. info.style.width = '100%';
  34. info.style.textAlign = 'center';
  35. info.innerHTML = 'Drag to change the view';
  36. container.appendChild( info );
  37. scene = new THREE.Scene();
  38. camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000 );
  39. camera.position.y = 150;
  40. camera.position.z = 500;
  41. scene.add( camera );
  42. controls = new THREE.TrackballControls( camera );
  43. var light = new THREE.PointLight( 0xffffff );
  44. light.position.set( 500, 500, 500 );
  45. scene.add( light );
  46. var light = new THREE.PointLight( 0xffffff, 0.25 );
  47. light.position.set( - 500, - 500, - 500 );
  48. scene.add( light );
  49. sphere = new THREE.Mesh( new THREE.SphereGeometry( 200, 20, 10 ), new THREE.MeshLambertMaterial( { shading: THREE.FlatShading } ) );
  50. scene.add( sphere );
  51. // Plane
  52. plane = new THREE.Mesh( new THREE.PlaneGeometry( 400, 400 ), new THREE.MeshBasicMaterial( { color: 0xe0e0e0 } ) );
  53. plane.position.y = - 200;
  54. scene.add( plane );
  55. renderer = new THREE.CanvasRenderer();
  56. // container.appendChild( renderer.domElement );
  57. effect = new THREE.AsciiEffect( renderer );
  58. effect.setSize( window.innerWidth, window.innerHeight );
  59. container.appendChild( effect.domElement );
  60. stats = new Stats();
  61. stats.domElement.style.position = 'absolute';
  62. stats.domElement.style.top = '0px';
  63. container.appendChild( stats.domElement );
  64. }
  65. //
  66. function animate() {
  67. requestAnimationFrame( animate );
  68. render();
  69. stats.update();
  70. }
  71. function render() {
  72. var timer = Date.now() - start;
  73. sphere.position.y = Math.abs( Math.sin( timer * 0.002 ) ) * 150;
  74. sphere.rotation.x = timer * 0.0003;
  75. sphere.rotation.z = timer * 0.0002;
  76. controls.update();
  77. effect.render( scene, camera );
  78. }
  79. </script>
  80. </body>
  81. </html>