Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Mathematica: Opacity and graphics

  1. Mar 19, 2012 #1

    I have the following graphic:
    Code (Text):

    Graphics[{Opacity[0.5], Rectangle[{0, 0}, {1, 3}]}]
    Say I want opacity to vary with x, e.g. with the expression opacity = x^2. Is there a way to do this? I checked out the "Help", but there were no examples of a varying opacity.

  2. jcsd
  3. Mar 19, 2012 #2


    Staff: Mentor

    Use Raster instead of Rectangle:

    Graphics[Raster[Table[{0, 0, 0, x/128}, {x, 128}, {256}]]]

    The elements of the Raster are {red, green, blue, opacity}.
  4. Mar 20, 2012 #3
    Thanks, it is kind of you to help me.

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook