Bokeh

Script-placed, blurred circles of colour form a faux bokeh background behind extruded text.

What you are seeing

The words SVG Wow 2010 in thick white bevelled letters at the centre of a charcoal background. Around them float soft translucent discs of green, blue, purple, red and amber, larger toward the edges. The arrangement changes on every load.

How it works

A script adds 50 circles at random positions. The further a circle is from the centre, the larger it is.

Each circle gets a low opacity, a colour from its position and one of three blur filters, so overlaps build into soft discs of light.

The title is a stack of offset use copies of one text element, which gives it depth, and clicking rotates the whole stack once.

History

Published on August 22, 2010. It also set the buffered-rendering hint on its background group.

Source

/buffered-rendering/bokeh.svg
<svg id="svgroot" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:html="http://www.w3.org/1999/xhtml" viewBox="0 0 1024 768">
  <title>Bokeh</title>
  <desc>Soft out-of-focus circles of colour drift across a dark background behind the extruded white words SVG Wow 2010. The circles are placed at random on each load. Click, or press Enter or Space, to spin the title once.</desc>
  <!-- Author: Erik Dahlström. License terms: see svg-wow.org. CC0 http://creativecommons.org/publicdomain/zero/1.0/
       Restoration: webfont replaced by a system stack, keyboard start added. -->
  <style>
    text { 
      text-anchor: middle;
      font: 80px "Arial Rounded MT Bold", "Trebuchet MS", Verdana, sans-serif;
      font-weight: 900;
      text-rendering: geometricPrecision;
    }
    :root { background: #222; cursor: pointer }
  </style>
  
  <linearGradient id="lg" x1="0" y1="0" x2="0" y2="1">
    <stop offset="0.4" stop-color="white"/>
    <stop offset="1" stop-color="gray"/>
  </linearGradient>
  <linearGradient id="lg2" x1="0" y1="1" x2="0" y2="0">
    <stop offset="0" stop-color="black"/>
    <stop offset="0.25" stop-color="darkgray"/>
    <stop offset="0.6" stop-color="gray"/>
    <stop offset="1" stop-color="#222"/>
  </linearGradient>
  <filter id="ds">
    <feGaussianBlur stdDeviation="2" in="SourceAlpha"/>
    <feOffset dy="2"/>
    <feComposite in="SourceGraphic"/>
  </filter>
  <filter id="tiltshift" x="0" y="0" width="1" height="1" primitiveUnits="objectBoundingBox">
    <feColorMatrix id="saturate1" type="saturate" values="2" result="saturate"/>
    <feGaussianBlur id="bottomblur" stdDeviation="4" y="0.6" height="0.4" in="saturate" result="bottomblur"/>
    <feGaussianBlur id="topblur" stdDeviation="4" height="0.4" in="saturate" result="topblur"/>
    <feComposite operator="atop" in2="saturate" in="topblur" k2="1" k3="1"/>
    <feComposite operator="atop" in="bottomblur" k2="1" k3="1" result="multiblur"/>
  </filter>
  <filter id="b2" filterUnits="userSpaceOnUse">
    <feGaussianBlur stdDeviation="10 0.1"/>
  </filter>
  <filter id="b5" filterUnits="userSpaceOnUse">
    <feGaussianBlur stdDeviation="50 10"/>
  </filter>
  <filter id="b10" filterUnits="userSpaceOnUse">
    <feGaussianBlur stdDeviation="100 20"/>
  </filter>
  <g id="bg" buffered-rendering="static">
  </g>
  <g filter="url(#ds)">
    <use xlink:href="#t" transform="translate(0,10)"/>
    <use xlink:href="#t" transform="translate(0,9)"/>
    <use xlink:href="#t" transform="translate(0,8)"/>
    <use xlink:href="#t" transform="translate(0,7)"/>
    <use xlink:href="#t" transform="translate(0,6)"/>
    <use xlink:href="#t" transform="translate(0,5)"/>
    <use xlink:href="#t" transform="translate(0,4)"/>
    <use xlink:href="#t" transform="translate(0,3)"/>
    <use xlink:href="#t" transform="translate(0,2)"/>
    <use xlink:href="#t" transform="translate(0,1)"/>
    <text id="t" x="50%" y="50%" fill="url(#lg2)" transform="translate(0,2)"><tref xlink:href="#top"/></text>
    <text x="50%" y="50%" fill="black" transform="translate(0,2)" stroke="black"><tref xlink:href="#top"/></text>
    <text x="50%" y="50%" fill="white" transform="translate(0,1)" stroke="white"><tref xlink:href="#top"/></text>
    <text id="top" x="50%" y="50%" fill="url(#lg)">SVG Wow 2010</text>
    
    <animateTransform id="anim" type="rotate" attributeName="transform" values="0 512 384; 360 512 384" dur="10s" begin="svgroot.click"/>
  </g>
  <g id="fg">
  </g>
  
  <script><![CDATA[
    (function() {
      function tref_fixup()
      {
        var elms = document.querySelectorAll("tref");
        // if no support for the SVGAnimatedString interface on tref elements
        if(elms.length && !elms[0].href)
        {
          for(var i = 0; i < elms.length; i++)
          {
            var text = document.getElementById(elms[i].getAttributeNS("http://www.w3.org/1999/xlink", "href").substr(1));
            elms[i].parentNode.textContent = text.textContent;
          }
        }
      }
      
      function attrs(attrs)
      {
        for(var attr in attrs)
          this.setAttribute(attr, attrs[attr]);
      }
      
      function getFill(x,y,maxx,maxy,normdist)
      {
        return "hsl(" + Math.sqrt((x/maxx)*(x/maxx)+(y/maxy)*(y/maxy))*360 + "," + 50+y/maxy + "%," + 60 + "%)";
      }
      
      function makeCircle(dest)
      {
        var root = document.documentElement;
        var c = document.createElementNS("http://www.w3.org/2000/svg", "circle");
        c.constructor.prototype.attr = attrs;
        var maxwidth = root.viewBox.baseVal.width;
        var maxheight = root.viewBox.baseVal.height;
        var midw = root.viewBox.baseVal.width/2;
        var midh = root.viewBox.baseVal.height/2;
        var cx = Math.random()*maxwidth;
        var cy = Math.random()*maxheight;
        c.attr({
          cx: cx, 
          cy: cy
        });
        
        var r = Math.sqrt((cx-midw)*(cx-midw)+(cy-midh)*(cy-midh))/5;
        var rmax = Math.sqrt(midw*midw + midh*midh);
        var normr = r/rmax;
        
        var filter = "none";
        if(normr > 0.7)
          filter = "url(#b10)";
        else if (normr > 0.3)
          filter = "url(#b5)";
        else
          filter = "url(#b2)";
        
        c.attr({
          cx: cx, 
          cy: cy,
          r: r, 
          "fill-opacity": Math.min(0.1,normr), 
          fill: getFill(cx,cy,maxwidth,maxheight,normr), 
          filter: filter
        });
              
        document.getElementById(dest).appendChild(c);

        // webkit seems fail on "fill:hsl(...)"
        if (!getComputedStyle(c, null).getPropertyValue("fill"))
        {
          c.attr({fill:"currentColor", style: "color:"+getFill(cx,cy,maxwidth,maxheight,normr)});
        }
      }
    
      tref_fixup(); // tref hack for firefox
      
      for(var i = 0; i < 50; i++)
        makeCircle("bg");

      document.addEventListener("keydown", function(evt) {
        if(evt.key === "Enter" || evt.key === " ")
        {
          evt.preventDefault();
          document.getElementById("anim").beginElement();
        }
      });
    })();
  ]]></script>
</svg>
/buffered-rendering/bokeh.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bokeh | SVG Wow!</title>
<meta name="description" content="Blurred circles of colour make a faux bokeh background behind extruded text, generated by script and SVG filters.">
<style>html,body{margin:0;height:100%;background:#111;color:#ddd;font:15px/1.45 system-ui,-apple-system,"Segoe UI",sans-serif}body{display:flex;flex-direction:column;min-height:100%}header{display:flex;flex-wrap:wrap;gap:4px 16px;align-items:baseline;padding:10px 16px}h1{font-size:18px;margin:0;color:#fff}p{margin:0;color:#aaa}a{color:#ffc14d}iframe{flex:1;width:100%;min-height:320px;border:0;background:#000;display:block}</style>
</head>
<body>
<header>
<h1>Bokeh</h1>
<p>Erik Dahlström, 2010. Reload for a new arrangement. Click to spin the title.</p>
<p><a href="/gallery/bokeh/">Gallery page</a> · <a href="bokeh.svg">Open the SVG</a></p>
</header>
<iframe src="bokeh.svg" title="Bokeh demo"></iframe>
</body>
</html>