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.
Code editor
You can make changes to the code below. Then
Reference
color
draw
fill
float
for
get
int
map
mouseX
mouseY
noise
point
rect
setup
size
stroke
void
width
color
draw
fill
float
for
get
int
map
mouseX
mouseY
noise
point
rect
setup
size
stroke
void
width
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); } ```