How to make a "sensitive zone" for clicks using a PImage, PShape, or PVector

edited August 2015 in How To...

hi guys, first of all i wnat to appologize for mi orthography (my mother idiom is spanish, not english).

well i'm new in processing (and programing) and i working on a proyect that involves the mouseClicked() event. i am working with 4 separate images, and if you clicked in the area of one of them, it will changed into anoter image. the thing is that my images aren't perfet squares nor ellipces. so creating the comant

if (moseX >= min X coordinate && mouseX <= max X coordinate && mouseY >= min Y coordinate && mouseY <= max Ycoordinate)

or using dist() can resolve my problem.

I want to know if i can create that "sensitive zone using a image, or a shape, or a vector, like transforming the position of the vertex or nodes in an area that the click responds to. Thansk for the time


  • edited August 2015

    "if (mouseX>=min(0,img.width) &&....) "

    apply value of mouseX,mouseY...

  • @Sinchai, the issue is that the images aren't rectangles so simple methods like that won't work.

    As for a possible solution, maybe you can implement the ray tracing algorithm described here? That is, if you manage to get a PShape of the contours of the image...

    Here's a skeleton for a possible implementation of the algorithm:

    PShape imageContour;
    PVector previous;
    int count;
    for(int i = 0; i < imageContour.getVertexCount(); i++)
      PVector p = imageContour.getVertex(i);
      //determine if horizontal line at height mouseY intersects with the line between the previous PVector and the p PVector
      //if so increment count
      previous = p;
    if(count%2 == 0) println("outside");
    else println("inside");
  • thanks @colouredmirrirball for your answer, but, i have a doubt, i am trying to match the mouseY and the count, but i really dont know how to do it. Anyways, if i have a progress i will let know :)

Sign In or Register to comment.