Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" >
  5. <title>Rotating Square</title>
  6.  
  7. <script id="vertex-shader" type="x-shader/x-vertex">
  8. attribute vec4 vPosition;
  9. uniform float theta;
  10.  
  11. void
  12. main()
  13. {
  14. float s = 0.3*sin( theta );
  15. float c = 0.4 * cos( theta );
  16.  
  17. gl_Position.x = -s * vPosition.y + c * vPosition.x + 0.4*sin(theta);
  18. gl_Position.y = s * vPosition.x + c * vPosition.y + 0.4*cos(theta);
  19. gl_Position.z = 0.0;
  20. gl_Position.w = 1.0;
  21. }
  22. </script>
  23.  
  24. <script id="fragment-shader" type="x-shader/x-fragment">
  25.  
  26. precision mediump float;
  27.  
  28. void
  29. main()
  30. {
  31.  
  32. float rateX = 3.0;
  33. float rateY = 5.0;
  34. float sinScaleX = 10.0;
  35. float sinScaleY = 300.0;
  36.  
  37. float lerpValue = gl_FragCoord.y / 500.0;
  38. lerpValue = cos(lerpValue*sinScaleY);
  39. if (lerpValue>0.3) lerpValue = 0.5*lerpValue;
  40.  
  41. float lerpValue2 = gl_FragCoord.x / 500.0;
  42. lerpValue2 = sin(lerpValue2*sinScaleX);
  43. if (lerpValue2>.7) lerpValue2 = 0.5*lerpValue2;
  44.  
  45. gl_FragColor = rateY * mix(vec4(12/255, 53/255, 169/255, 1.0), vec4(0.3, 0.3, 0.0, 1.0), lerpValue)
  46. + rateX * mix(vec4(1.5, 0.2, 0.3, 1.0), vec4(0.4, 0.4, 0.2, 1.0), lerpValue2);
  47. }
  48. </script>
  49.  
  50. <script type="text/javascript" src="../Common/webgl-utils.js"></script>
  51. <script type="text/javascript" src="../Common/initShaders.js"></script>
  52. <script type="text/javascript" src="../Common/MV.js"></script>
  53. <script type="text/javascript" src="rotatingSquare1.js"></script>
  54. </head>
  55.  
  56. <body>
  57. <canvas id="gl-canvas" width="1024" height="1024">
  58. Oops ... your browser doesn't support the HTML5 canvas element
  59. </canvas>
  60. </body>
  61. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement