Last active
December 8, 2016 10:51
-
-
Save notalentgeek/3f27bcab6fc9fed7f0209ba6e173a8af to your computer and use it in GitHub Desktop.
Processing sketch to change alpha of a color programmatically.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
color alphaColor; | |
// I test this program using red color. | |
// But you can use any color you want. | |
color mainColor = color(255, 0, 0); | |
// The least alpha value is 0 while | |
// the most alpha value is 255. | |
// This variable is the starting alpha | |
// value. | |
int alphaValue = 255; | |
void setup(){} | |
void draw(){ | |
background(255); | |
// This is the magic using bit shifting. | |
alphaColor = alphaValue << 030; | |
fill(mainColor & ~#000000 | alphaColor); | |
// For this example I will create an ellipse | |
// that has its color change gradually. | |
ellipse( | |
width/2, | |
height/2, | |
width/2, | |
height/2 | |
); | |
// Change the alpha color (opacity) gradually. | |
alphaValue --; | |
// Turn the fill color back into default. | |
fill(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment