Mathematica Mathematica: Opacity and graphics

Click For Summary
The discussion centers on how to create a graphic in which the opacity varies with the x-coordinate. The original poster seeks a method to implement this variation using the expression opacity = x^2. A suggestion is made to use the Raster function instead of Rectangle, which allows for the specification of opacity within the color elements. The proposed solution involves creating a Raster that generates a table of colors, including varying opacity values based on the x-coordinate. This approach effectively addresses the need for dynamic opacity in the graphic.
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.
 
Physics news on Phys.org
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}.
 
Thanks, it is kind of you to help me.Niles.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 0 ·
Replies
0
Views
1K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 1 ·
Replies
1
Views
3K