Skip to content

Instantly share code, notes, and snippets.

@isu3ru
Created October 20, 2017 04:12
Show Gist options
  • Save isu3ru/153486f3dbc816b0dd2bea18341a8668 to your computer and use it in GitHub Desktop.
Save isu3ru/153486f3dbc816b0dd2bea18341a8668 to your computer and use it in GitHub Desktop.
Java code to get each hexadecimal value from 100% to 0% alpha
for (double i = 1; i >= 0; i -= 0.01) {
i = Math.round(i * 100) / 100.0d;
int alpha = (int) Math.round(i * 255);
String hex = Integer.toHexString(alpha).toUpperCase();
if (hex.length() == 1)
hex = "0" + hex;
int percent = (int) (i * 100);
System.out.println(String.format("%d%% — %s", percent, hex));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment