I build complex images using graphics primitives but I want to fade out some so I can place others or text with the transition not being abrupt. This would be easy if we could use Opacity inside a LinearGradientFilling command, but that only takes colors. This answer produces transparency in images, but converting that to transparency inside Graphics seems quite messy, requiring Rasterizing Image. My workaround has been to create a Table of Rectangles of increasing Opacity as in the example below. I was hoping a simpler approach might exist, akin to LinearGradientFilling[{Directive[White,Opacity@1],Directive[White,Opacity@0]}],Rectangle[].


  Black, Disk[],
  Rectangle[{-1, lowPt = -.3}, {(xstart = -.2), highPt = -.1}],
  Table[{Opacity[1 - i/numRectangles], 
    Rectangle[{xstart + 
       i*(width = ((xend = 0) - xstart)/numRectangles), 
      lowPt}, {xstart + (i + 1)*width, highPt}]}, {i, 
    0, (numRectangles = 50) - 1}]

Thanks in advance!

  • 2
    $\begingroup$ LinearGradientFilling doesn't take Directives, but you can include the Opacity as part of the color. Something like Graphics[{Purple, Rectangle[], LinearGradientFilling[{RGBColor[0, 0, 0, 0], RGBColor[0, 0, 0, 1]}], Rectangle[]}] should do. $\endgroup$
    – ihojnicki
    Aug 14, 2023 at 13:11
  • $\begingroup$ @ihojnicki Super, exactly what I was seeking! Would you like to write it up as an answer that I would accept? $\endgroup$
    – Nicholas G
    Aug 14, 2023 at 21:54


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.