Beginner Color Help

How do I make something happen when like a line is on a specific colour?

it would help to see your code.

Generically speaking, you could check the color of the end-point of the line by using color cComp=get(x,y);

When myColor is your color you want to check against:

Then say

if(myColor==cComp) { 
     println("Hello");   
}

Here is an example:



color cComp=0; 
color myColor=0;
String text1="Is the color you clicked on RED ? ";
//
// ---------------------------------------------------------------
//
void setup() {
  // init
  size(800, 600);
  myColor=color (255, 0, 0);
} // func 

void draw() { 
  background(255);

  fill(255, 0, 0); // RED  
  triangle(30, 75, 
    58, 20, 
    300, 75);
  if (myColor==cComp) { 
    text( text1+"Yes   "+colorAsString(), 400, 400);
  } else {
    text( text1+"NO    "+colorAsString(), 400, 400);
  }

  fill(0, 0, 255);
  rect(400, 200, 44, 44); 
  //
} // func 
//

void mousePressed() {
  cComp=get(mouseX, mouseY);
}//func

String colorAsString() {
  return 
    str(int(red(cComp))) 
    + ","  +
    str(int(green(cComp))) 
    + "," +
    str(int(blue(cComp))) ;
}
//

It is the question if the ENTIRE line is placed on the same color:

  • Then you need to check the whole line pixel by pixel prior to drawing it
2 Likes

I just realized how to do it but thanks.

1 Like