Processing Month, Day 11 - Painting, Part 2

Posted by Jan Vantomme on 11 May 2011.
Tags: ,

The brush algorithm we’ll use today will be the same as the one we used yesterday in Painting, Part 1. But we won’t use the HSB color mode anymore. We’ll get our colors from an image, just like we did in the Circular Pixels sketch on day 9.

The problem with picking a color from an image, is that the color isn’t transparent. So I wrote a quick function that returns a transparent color. Note that this function doesn’t start with the void keyword. This one starts with the color keyword because the function returns a color. The function gets the individual red, green and blue components of the color with a technique called bit shifting. The code is hard to read, but it is a lot faster than the red(), green() and blue() functions.

color getTransparentColorcolor cfloat a )
    int r 
= (>> 16) & 0xff;
int g = (>> 8) & 0xff;
int b 0xff;    

You can use the function by setting the value for the first parameter to the color value for the current mouse position. The second parameter is a number between 0 and 255, where zero is full transparency, and 255 is no transparency.

color c getTransparentColorimg.getmouseXmouseY ), 64 );


Here are the original image I used and two paintings made with the sketch.

The original image used to create the painting.

Painting with Processing, based on an image.

Painting with Processing, based on an image.



Download the example for Procesing Day 11.

Tweet this article

Oldskool Comments (1)

Gravatar for WILL

From: WILL
Date: 11.05.2011

Awesome one !

Top · Permanent link to this comment