Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is really wacky but it does what you want without getting imageData involved.</p> <p>The thing that came to mind was that you want the exact functionality that paths themselves have on the canvas when you stroke them. To quote the spec:</p> <blockquote> <p>As a result of how the algorithm to trace a path is defined, overlapping parts of the paths in one stroke operation are treated as if their union was what was painted.</p> </blockquote> <p>You can read more about that <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#trace-a-path" rel="nofollow noreferrer">here.</a></p> <p>Anyway, what you'd want, essentially, is a blurry path of nothing but arcs that you can stroke once and you'd perfectly get the effect you were looking for.</p> <p>The only problem is that there is no way to make a blurry path in canvas. Or almost no way.</p> <p>Instead of using the path itself we can use the <em>shadow of a path</em> in order to simulate blurry circles that obey the same rules that paths do.</p> <p>The only problem there, then, is that you don't want to see the actual path, you just want to see the shadow of it. Making the stroke transparent won't work: A shadow will only draw will not draw at a higher opacity than the thing it is shadowing.</p> <p>But shadows do have the properties <code>shadowOffsetX</code> and <code>shadowOffsetY</code>, which are typically used to shift the shadow by a pixel or two to make the illusion of a light source.</p> <p>But what if we draw the shadows so far away that you can't see them? Or rather, what if we draw the <em>paths</em> so far away that you can't see them, all you can see are the shadows?</p> <p>Well that happens to do the trick. Here is a quick result, your original code is on the top and the shadows are the second canvas:</p> <p><img src="https://i.stack.imgur.com/nJeUb.png" alt="enter image description here"></p> <p>It's not exactly what you had before in terms of gradients and size but its very close and I'm sure that by fiddling with the values you can get it even closer. A couple of console.log's confirm that the thing we want, an alpha that does not go above 124 (out of 255) is correctly occurring in the places where it used to be 143 and 134 doing it the old way.</p> <p>The fiddle to see the code in action: <a href="http://jsfiddle.net/g54Mz/" rel="nofollow noreferrer">http://jsfiddle.net/g54Mz/</a></p> <p>So there you have it. Getting the effect of the union of two radial gradients is possible without <code>imageData</code> if you use shadows and offset the actual paths so much that they are off the screen.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload