Mathematica: Opacity and graphics

  • Context: Mathematica 
  • Thread starter Thread starter Niles
  • Start date Start date
  • Tags Tags
    Graphics Mathematica
Click For Summary
SUMMARY

The discussion focuses on varying opacity in Mathematica graphics. The user initially attempts to set a constant opacity using the command Graphics[{Opacity[0.5], Rectangle[{0, 0}, {1, 3}]}]. Niles suggests using Raster instead of Rectangle to achieve variable opacity, demonstrating this with the command Graphics[Raster[Table[{0, 0, 0, x/128}, {x, 128}, {256}]]]. This method allows for dynamic opacity adjustments based on the x-value.

PREREQUISITES
  • Familiarity with Mathematica graphics functions
  • Understanding of opacity and color representation in graphics
  • Knowledge of the Raster function in Mathematica
  • Basic programming skills in Mathematica syntax
NEXT STEPS
  • Explore the Raster function in detail within Mathematica documentation
  • Learn about dynamic graphics in Mathematica using Manipulate
  • Investigate color models and their application in Mathematica graphics
  • Experiment with creating custom opacity functions in Mathematica
USEFUL FOR

This discussion is beneficial for Mathematica users, graphic designers, and data visualizers looking to enhance their graphics with variable opacity effects.

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
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K