KaoSDlanor

KaoShader Example

Mar 7th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.19 KB | None | 0 0
  1. <html>
  2.   <head>
  3.     <script src="assets/js/jquery-3.1.1.min.js"></script>
  4.     <script src="assets/js/KaoShader.js"></script>
  5.  
  6.     <script type="text/javascript">
  7.       $(document).ready(() => {
  8.         try {
  9.           var time_start = +new Date();
  10.           var canvas = $('<canvas class="main"></canvas>')
  11.             .appendTo(document.body)
  12.             .KaoShader({
  13.               shaderF : `
  14.                 #define PI 3.1415926538
  15.                 precision mediump float;
  16.                 varying vec2 c_pos;
  17.                 varying vec2 a_pos;
  18.                 uniform float time;
  19.  
  20.                 float coerce(float ang)
  21.                 {
  22.                   return mod(mod(ang,PI*2.)+PI*2.,PI*2.);
  23.                 }
  24.  
  25.                 float color(float i_ang, float index, float p_ang)
  26.                 {
  27.                   float t_ang = i_ang * index;
  28.                   float d_ang = coerce( abs(t_ang - p_ang) );
  29.                   return max(i_ang - d_ang, i_ang - PI*2. + d_ang) / i_ang;
  30.                 }
  31.  
  32.                 void main(void)
  33.                 {
  34.                   float p_ang = coerce( atan(c_pos.y,c_pos.x) + time / 10. );
  35.                   float i_ang = PI * 2. / 3.;
  36.  
  37.                   float c_dist = sqrt(pow(c_pos.x,2.)+pow(c_pos.y,2.));
  38.  
  39.                   vec3 col = vec3(
  40.                     color(i_ang,0.,p_ang),
  41.                     color(i_ang,1.,p_ang),
  42.                     color(i_ang,2.,p_ang)
  43.                   ) * c_dist;
  44.  
  45.                     gl_FragColor = vec4(col,1.);
  46.                 }
  47.               `,
  48.               uniforms : {
  49.                 time : 0,
  50.               },
  51.             });
  52.  
  53.           setInterval(() => {
  54.             var time_stamp = +new Date() - time_start;
  55.             canvas
  56.               .KaoShader_input({time:time_stamp / 1000})
  57.               .KaoShader_draw();
  58.           },100);
  59.         } catch(e) {
  60.           console.error(e);
  61.         }
  62.       });
  63.     </script>
  64.     <style type="text/css">
  65.       .main {
  66.         position : fixed;
  67.         top : 0;
  68.         bottom : 0;
  69.         left : 0;
  70.         right : 0;
  71.         width : 100vw;
  72.         height : 100vh;
  73.       }
  74.     </style>
  75.   </head>
  76.   <body>
  77.  
  78.   </body>
  79. </html>
Advertisement
Add Comment
Please, Sign In to add comment