webgl_effects_ascii.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - effects - ascii</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. padding:0;
  10. margin:0;
  11. font-weight: bold;
  12. overflow:hidden;
  13. }
  14. #info {
  15. position: absolute;
  16. top: 0px; width: 100%;
  17. color: #000000;
  18. padding: 5px;
  19. font-family:Monospace;
  20. font-size:13px;
  21. text-align:center;
  22. z-index:1000;
  23. }
  24. a {
  25. color: #ff0000;
  26. }
  27. #webglmessage a { color:#da0 }
  28. </style>
  29. </head>
  30. <body>
  31. <div id="info"><a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - effects - ascii</div>
  32. <script src="../build/three.js"></script>
  33. <script src="js/controls/TrackballControls.js"></script>
  34. <script src="js/effects/AsciiEffect.js"></script>
  35. <script src="js/WebGL.js"></script>
  36. <script>
  37. if ( WEBGL.isWebGLAvailable() === false ) {
  38. document.body.appendChild( WEBGL.getWebGLErrorMessage() );
  39. }
  40. var camera, controls, scene, renderer, effect;
  41. var sphere, plane;
  42. var start = Date.now();
  43. init();
  44. animate();
  45. function init() {
  46. camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000 );
  47. camera.position.y = 150;
  48. camera.position.z = 500;
  49. controls = new THREE.TrackballControls( camera );
  50. scene = new THREE.Scene();
  51. scene.background = new THREE.Color( 0xf0f0f0 );
  52. var light = new THREE.PointLight( 0xffffff );
  53. light.position.set( 500, 500, 500 );
  54. scene.add( light );
  55. var light = new THREE.PointLight( 0xffffff, 0.25 );
  56. light.position.set( - 500, - 500, - 500 );
  57. scene.add( light );
  58. sphere = new THREE.Mesh( new THREE.SphereBufferGeometry( 200, 20, 10 ), new THREE.MeshLambertMaterial() );
  59. scene.add( sphere );
  60. // Plane
  61. plane = new THREE.Mesh( new THREE.PlaneBufferGeometry( 400, 400 ), new THREE.MeshBasicMaterial( { color: 0xe0e0e0 } ) );
  62. plane.position.y = - 200;
  63. plane.rotation.x = - Math.PI / 2;
  64. scene.add( plane );
  65. renderer = new THREE.WebGLRenderer( { antialias: true } );
  66. renderer.setPixelRatio( window.devicePixelRatio );
  67. renderer.setSize( window.innerWidth, window.innerHeight );
  68. // document.body.appendChild( renderer.domElement );
  69. effect = new THREE.AsciiEffect( renderer );
  70. effect.setSize( window.innerWidth, window.innerHeight );
  71. document.body.appendChild( effect.domElement );
  72. //
  73. window.addEventListener( 'resize', onWindowResize, false );
  74. }
  75. function onWindowResize() {
  76. camera.aspect = window.innerWidth / window.innerHeight;
  77. camera.updateProjectionMatrix();
  78. renderer.setSize( window.innerWidth, window.innerHeight );
  79. effect.setSize( window.innerWidth, window.innerHeight );
  80. }
  81. //
  82. function animate() {
  83. requestAnimationFrame( animate );
  84. render();
  85. }
  86. function render() {
  87. var timer = Date.now() - start;
  88. sphere.position.y = Math.abs( Math.sin( timer * 0.002 ) ) * 150;
  89. sphere.rotation.x = timer * 0.0003;
  90. sphere.rotation.z = timer * 0.0002;
  91. controls.update();
  92. effect.render( scene, camera );
  93. }
  94. </script>
  95. </body>
  96. </html>