Wiki

Clone wiki

setalpha / Home

setalpha

Home | Color | setAlpha | About

Welcome to setalpha, a simple library that makes working with css colors - in particular, setting alpha levels - much more convenient!

The library consists of an abstract, convenience class called Color and the eponymous alpha-setting function, setAlpha.

Basic use

It is often useful to have access to the same css color, but with different alpha levels, when designing content for the web.

The setalpha library allows us to easily set the alpha level of a CSS color. The following code, for example, creates a string rgba expression that represents the CSS color midnightblue with an alpha level of 0.3, and stores it the variable color.

String color = setAlpha(Color.midnightBlue, 0.3);

The variable color may now be used in setting the style of an html element, the strokeStyle or fillStyle properties of a canvas context, or anywhere that css colors may be used.

The following image was created (see example > example.html) by repeatedly randomly selecting a css color and then drawing a randomly positioned circle with different alpha levels for the stroke, fill and text.

Updated