svg-filter-animation.svg 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?xml version="1.0" standalone="no"?>
  2. <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
  3. <!--
  4. Copyright (C) 2010 University of Szeged
  5. Copyright (C) 2010 Zoltan Herczeg
  6. Copyright (C) 2010 Gabor Loki
  7. All rights reserved.
  8. Redistribution and use in source and binary forms, with or without
  9. modification, are permitted provided that the following conditions
  10. are met:
  11. 1. Redistributions of source code must retain the above copyright
  12. notice, this list of conditions and the following disclaimer.
  13. 2. Redistributions in binary form must reproduce the above copyright
  14. notice, this list of conditions and the following disclaimer in the
  15. documentation and/or other materials provided with the distribution.
  16. THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY
  17. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19. PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF SZEGED OR
  20. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  24. OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. -->
  28. <svg width="100%" height="100%" version="1.1" xmlns="http://www.w3.org/2000/svg">
  29. <rect x="0%" y="0%" width="100%" height="100%" fill="black" />
  30. <defs>
  31. <filter id="filt" filterUnits="objectBoundingBox" x="0" y="0" width="100%" height="100%">
  32. <feTurbulence baseFrequency="0.03" numOctaves="4" seed="67" result="turb"/>
  33. <feGaussianBlur in="SourceGraphic" primitiveUnits="objectBoundingBox" stdDeviation="1" result="blur"/>
  34. <feComposite in="turb" in2="blur" operator="arithmetic" k2="0.3" k3="1" result="comp"/>
  35. <feDiffuseLighting in="comp" primitiveUnits="objectBoundingBox" diffuseConstant="1" lighting-color="white" surfaceScale="10" result="light" >
  36. <feSpotLight id="light" x="0" y="300" z="200" pointsAtX="-200" pointsAtY="100" pointsAtZ="0" limitingConeAngle="90" specularExponent="20" />
  37. </feDiffuseLighting>
  38. <feSpecularLighting in="comp" primitiveUnits="objectBoundingBox" diffuseConstant="1" lighting-color="#A66102" surfaceScale="10" result="ambient" >
  39. <feDistantLight azimuth="0" elevation="90" />
  40. </feSpecularLighting>
  41. <feComposite in="light" in2="ambient" operator="arithmetic" k2="1.2" k3=".8"/>
  42. </filter>
  43. </defs>
  44. <g filter="url(#filt)" fill="white" stroke="black" onclick="start()">
  45. <rect x="0" y="0" width="400" height="5" />
  46. <rect x="0" y="0" width="5" height="200" />
  47. <rect x="0" y="195" width="400" height="5" />
  48. <rect x="395" y="0" width="5" height="200" />
  49. <text font-size="150" font-weight="bold" x="40" y="150">SVG</text>
  50. </g>
  51. <text id="fps" x="150" y="240" font-size="20" fill="white" stroke="white">afps:</text>
  52. <text x="30" y="265" font-size="20" font-weight="bold" fill="white" stroke="white">click on the image to start the animation</text>
  53. <script>
  54. <![CDATA[
  55. var light_x = document.getElementById('light').x;
  56. var light_y = document.getElementById('light').y;
  57. var light_pointsAtX = document.getElementById('light').pointsAtX;
  58. var light_pointsAtY = document.getElementById('light').pointsAtY;
  59. var fps = document.getElementById('fps');
  60. var round = Math.round
  61. var startDate = 0;
  62. var frameCounter = 0;
  63. var phase = 0;
  64. function anim() {
  65. switch(phase) {
  66. case 0:
  67. light_pointsAtX.baseVal += 10;
  68. if (light_pointsAtX.baseVal >= 380)
  69. ++phase;
  70. break;
  71. case 1:
  72. light_x.baseVal += 10;
  73. light_pointsAtX.baseVal -= 10;
  74. if (light_x.baseVal >= 450) {
  75. ++phase;
  76. waitCounter = 0;
  77. }
  78. break;
  79. case 2:
  80. light_y.baseVal -= 5;
  81. if (light_y.baseVal <= -100)
  82. ++phase;
  83. break;
  84. case 3:
  85. light_pointsAtX.baseVal += 10;
  86. if (light_pointsAtX.baseVal >= 450) {
  87. light_x.baseVal = 0;
  88. light_pointsAtX.baseVal = -200;
  89. light_y.baseVal = 300;
  90. light_pointsAtY.baseVal = 100;
  91. phase = 0;
  92. }
  93. break;
  94. }
  95. frameCounter++;
  96. fps.textContent = "afps: " +(round(frameCounter * 100000 / (new Date() - startDate)) / 100);
  97. }
  98. function start() {
  99. if (!startDate) {
  100. startDate = new Date();
  101. setInterval(anim,1);
  102. }
  103. }
  104. //]]>
  105. </script>
  106. </svg>