Alternating AWT graphics colour

It is possible to draw 2D colours in such a way that it inverts colours behind it, like in the screenshot below:

line colour

This can be done by enabling “XOR Colour mode” and by using…

Color.WHITE

…this is because white has an RGB value of 255,255,255, and XOR’ing these values will cause the alternating effect.

The following code example shows this:

graphics.setXORMode(Color.WHITE);
graphics.drawLine(x, delegate.getXAxisHeight(), x, delegate.getDiagramRect().height + delegate.getXAxisHeight());
graphics.setColor(Color.BLACK);

Don’t forget to save the previous colour (using graphics.getColor())and then reset it after drawing this alternative-coloured line.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s