Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7782657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:36:37+00:00 2026-06-01T19:36:37+00:00

I’m currently working on a heatmap.js fix and I was wondering whether anyone knows

  • 0

I’m currently working on a heatmap.js fix and I was wondering whether anyone knows if it’s possible to achive the following effect with <canvas>‘s 2d rendering context.

  • I have a radial gradient from black (alpha 0.5) to transparent 40pixel radius. center of the radial gradient is at x=50, y=50
  • I have another radial gradient from black (alpha 0.5) to transparent, 40pixel radius. center of the radial gradient is at x=80, y=50

The two gradients are overlapping. My problem now is: the overlapping area gets added up together resulting in a higher alpha value than the radial gradients centers and thus showing wrong data (e.g. hotter areas in a heatmap because of those additions between the gradients)

Have a look at the following gist, by executing it in your console you can see the problem.

Expected behaviour would be:
Darkest areas are the gradients centers, the overlapping area of the two gradients merges but doesn’t add up.

After seeing that none of the globalCompositeOperations resulted in the expected behaviour I tried combinations of those operations.
A way I thought it maybe would be possible was the following:

  • draw first gradient
  • use compositeOperation ‘destination-out’
  • draw second gradient -> substracts overlapping area from the first gradient
  • use compositeOperation ‘source-over’
  • draw second gradient again

But unfortunately I didn’t find a combination that worked. I’d love to hear your feedback, thanks in advance!

PS: I know this could be done by manipulating the pixels manually, but I was wondering whether there’s an easier, more elegant and faster solution for that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:36:39+00:00Added an answer on June 1, 2026 at 7:36 pm

    This is really wacky but it does what you want without getting imageData involved.

    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:

    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.

    You can read more about that here.

    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.

    The only problem is that there is no way to make a blurry path in canvas. Or almost no way.

    Instead of using the path itself we can use the shadow of a path in order to simulate blurry circles that obey the same rules that paths do.

    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.

    But shadows do have the properties shadowOffsetX and shadowOffsetY, which are typically used to shift the shadow by a pixel or two to make the illusion of a light source.

    But what if we draw the shadows so far away that you can’t see them? Or rather, what if we draw the paths so far away that you can’t see them, all you can see are the shadows?

    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:

    enter image description here

    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.

    The fiddle to see the code in action: http://jsfiddle.net/g54Mz/

    So there you have it. Getting the effect of the union of two radial gradients is possible without imageData if you use shadows and offset the actual paths so much that they are off the screen.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I am currently running into a problem where an element is coming back from
Does anyone know how can I replace this 2 symbol below from the string
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.