How to play a sound when ( colorFromGet == pas )?

int x=1;
int y=1;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.awt.Rectangle;
color pas = color(11, 96, 133);

Robot robot;
void setup() {
  size(1500, 3000);
  try {
    robot = new Robot();
  catch (Exception e) {
void draw() {
  Rectangle r = new Rectangle(y, x, width, height);
  BufferedImage img1 = robot.createScreenCapture(r);
  PImage img2 = new PImage(img1);
  image(img2, 0, 0);
  color colorFromGet = get(x,y);

if ( colorFromGet  == pas ) //here it checks if they are the same


Please format your code as a courtesy to the community helping you:


And many examples in the Processing application to try:


Give it a try!


what did i do wrong in formatting this time i thought i did it proerly?

go back, edit your post using the pen symbol underneath it.

Select the entire code section and click </> symbol in the small command bar


Your code is confusing.

What is your intention?

As has been said please write your goals and questions in the text section and not only in the title.

i am screen recording my screen, and want it to see if a specific color is on that screen and if it is it has to play a sound

with size(1500, 3000); there is hardly much else on your screen than your Sketch?

Why do you make so many screenshots? ONE should be enough. In setup().

And then go over it with a nested for loop (2 fors) and check the color.

When you just say x++ y++ in the same frame of draw() you’re only testing the diagonal points of the center line…

but how do you play a sound when (colorFromGet== pas) with this code?

seriously? Your code can’t find a color as I just explained. It doesn’t search your screenshot.

Read Images and Pixels \

Sound (WHEN and only when you developed your Sketch, now it’s of no use): SoundFile \ Language (API) \ Processing 3+

doesnt it scan every line one by one if you add 1 to x and y the whole time?

err… NO

first of all, read the tutorial there is a code how to go over each pixel in an image/screenshot

think about it first time draw() runs both are 0, second time both (!) are 1 etc. - you only scan the diagonal “” of the image

what you need is:

  • x is 0 (first row of the image) y goes from 0 to height (x stays 0);
  • x is 1 (2nd row of the image) y goes from 0 to height;
  • x is 2 (2nd row of the image) y goes from 0 to height;

That’s achieved with a nested for loop

for (x....................
     for (y........
           COMPARE ---> play sound

what is a nested for loop. im learning with a youtube channel and i havent heard about that yet

read the tutorial

it has an example without nested for loop, just ONE for-loop


Take the following simple example. This program sets each pixel in a window to a random grayscale value. The pixels array is just like an other array, the only difference is that we don’t have to declare it since it is a Processing built-in variable.

Example: Setting Pixels

size(200, 200); // Before we deal with pixels loadPixels();
 // Loop through every pixel 

for (int i = 0; i < pixels.length; i++) { 
// Pick a random number, 0 to 255 
float rand = random(255); 

// Create a grayscale color based on random number 
color c = color(rand); 

// Set pixel at that location to random color 
pixels[i] = c; 

// When we are finished dealing with pixels 


(this code changes the pixels, you only want read them. So change this. But it’s the correct way to go through ALL points. Also it works on the Sketch surface and not on an image, but the principle is the same, see below)

as explained here: PImage \ Language (API) \ Processing 3+

just search the screenshot image and NOT display the screenshot and DON’T search the screen using get directly.

use loadPixels() and get on the image directly