067-svg-geometry.html 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>067 SVG geometry and paint</title>
  6. <style>
  7. body { background: #ffffff; color: #202020; font-family: sans-serif;
  8. margin: 12px; font-size: 18px; }
  9. .pane { float: left; width: 200px; height: 140px; margin-right: 20px;
  10. background: #eeeeee; }
  11. .icon { fill: currentColor; color: #008000; }
  12. #result { clear: both; background: #ffc8c8; color: #000000; padding: 8px;
  13. margin-top: 12px; }
  14. </style>
  15. </head>
  16. <body>
  17. <h1>067 &mdash; SVG geometry and paint</h1>
  18. <p>Filled curves, arcs, circles, groups with transforms, &lt;use&gt; of a
  19. symbol, fill-rule, strokes and gradient paint. Expected: a blue disc, a
  20. red ring with a hole, a green chevron, a black stroked zigzag and a
  21. mid-blue square (the average of its gradient stops).</p>
  22. <div class="pane">
  23. <svg width="200" height="140" viewBox="0 0 200 140">
  24. <defs>
  25. <linearGradient id="g1"><stop offset="0" stop-color="#0000ff"/>
  26. <stop offset="1" style="stop-color:#000080"/></linearGradient>
  27. <symbol id="chev" viewBox="0 0 24 24">
  28. <path d="M9 5l7 7-7 7-1.4-1.4L13.2 12 7.6 6.4z"/>
  29. </symbol>
  30. </defs>
  31. <circle id="disc" cx="35" cy="35" r="25" fill="#2040c0"/>
  32. <g fill="#c02020" transform="translate(100 35)">
  33. <path id="ring" fill-rule="evenodd"
  34. d="M0-25a25 25 0 1 1 0 50a25 25 0 1 1 0-50zM0-12a12 12 0 1 0 0 24a12 12 0 1 0 0-24z"/>
  35. </g>
  36. <use class="icon" href="#chev" x="140" y="10" width="50" height="50"/>
  37. <polyline id="zig" points="10,120 40,80 70,120 100,80" fill="none"
  38. stroke="#000000" stroke-width="4"/>
  39. <rect id="grad" x="130" y="80" width="50" height="50" fill="url(#g1)"/>
  40. </svg>
  41. </div>
  42. <p><span id="c1" style="color:#2040c0">blue</span>
  43. <span id="c2" style="color:#c02020">red</span></p>
  44. <div id="result">checking...</div>
  45. <script>
  46. setTimeout(function () {
  47. function F(id, p) { return getComputedStyle(document.getElementById(id))[p]; }
  48. var disc = F('disc', 'fill'), ring = F('ring', 'fill'),
  49. zig = F('zig', 'fill'), zs = F('zig', 'stroke'),
  50. bg = F('disc', 'backgroundColor');
  51. var ok = disc === F('c1', 'color') && ring === F('c2', 'color') &&
  52. zig === 'none' && zs === 'rgb(0, 0, 0)' &&
  53. bg === 'rgba(0, 0, 0, 0)';
  54. var r = document.getElementById('result');
  55. if (r) {
  56. r.style.background = ok ? '#c8f0c8' : '#ffc8c8';
  57. r.textContent = (ok ? 'SVGPAINT-OK ' : 'SVGPAINT-FAIL ') + disc + ' ' +
  58. ring + ' ' + zig + '/' + zs + ' bg=' + bg;
  59. }
  60. }, 300);
  61. </script>
  62. </body>
  63. </html>