Vertical opacity gradient in a polygon

Hi. My intent with this is a bit complicated, but I’ll try my best to explain it, and if anyone needs clarification, please ask.

My goal is to create a vertical opacity gradient within a polygon (that is, a gradient of the opacity, where the change in opacity is vertical). What I’m trying to do is show the changes in saturation of a cloud.

My question: is this possible? I want to be able to input a value of where the opacity starts, as well as input a value of where the opacity ends (ex: opacity starts at 1.00, and opacity ends at 0.75).

Based on the thread here, I would think so… but I haven’t tried it yet.
Can you share a link to an activity/screen where you want the effect?

1 Like

Desmos has an example called Hue Gradient on one of the demo pages that seems related to what you want to accomplish. Using the same technique of combining many lines to look like a rectangle, here is a variation with an opacity gradient:

A couple drawbacks:

  • Setting the number of lines is dependent on screen size and zoom level. The link I provided looks like a smooth gradient on my large laptop screen but just a plain, opaque rectangle on my phone screen.
  • I don’t know how to adapt this technique for an arbitrary polygon. It’s straightforward for rectangles with sides parallel to the gridlines but could get complicated very quickly in other cases.

Hopefully that’s a helpful starting point! I’d love to see other solutions, too.

Take 2. Here is a more flexible approach that will work with any convex polygon: Polygon Opacity Gradient.

Instead of combining lots of lines with different opacity, it layers polygons (via systems of inequalities) to create the opacity gradient. There are a lot of calculations going on under the hood, so it runs slowly and is more suitable for creating a static graph than a dynamic interaction.

1 Like

That worked great! Thanks for the help!