Mathematica: Opacity and graphics

2 replies · 3K views · last reply
Niles
Messages
1,834
Reaction score
0
Hi

I have the following graphic:
Code:
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.


Niles.
 
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}.