Learn creative coding writing simple programs

81. How to read the color of a pixel

With the get() function we can read the color of any pixel in our program window. We can specify which pixel we are interested in by using x and y coordinates as parameters. For example, color mycolor = get(100, 200); would grab the color of pixel 100, 200 and put that color into the mycolor variable. You can use this on many different ways. For instance you could grab the color of the pixel under the mouse pointer and use it for drawing something. Or if you wanted to draw a shape at a certain place, you could observe the color of pixels near that place. Now you will be able to draw things that depend on things which were previously drawn in the screen.

Tags: get, read, pixel

Code editor

You can make changes to the code below. Then

Questions and comments

Try to stay close to the topic of this episode. Use the Processing forums for help with unrelated Processing projects (or hire me for help ;-)

To indicate that a word in your comment is code, use the `backtick`. Example
Do `float` and `int` smell similar?
To highlight code blocks, surround it with ``` code-fences ``` like this:
``` void setup() { size(600, 600); } ```