Skip to content

Instantly share code, notes, and snippets.

@notalentgeek
Last active December 8, 2016 10:51
Show Gist options
  • Save notalentgeek/3f27bcab6fc9fed7f0209ba6e173a8af to your computer and use it in GitHub Desktop.
Save notalentgeek/3f27bcab6fc9fed7f0209ba6e173a8af to your computer and use it in GitHub Desktop.
Processing sketch to change alpha of a color programmatically.
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