Help with colour detection please!
Author |
Message |
RathcoM
|
Posted: Fri Nov 27, 2009 4:05 pm Post subject: Help with colour detection please! |
|
|
Lets say i have a region that is a certain colour inside of my applet, and i have another object that can potentially overlap the said region.
Can anybody give me an idea of how i can possibly approach this situation, such that upon overlapping, "x" event will occur?
Thank you in advance for your expertise. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Fri Nov 27, 2009 4:20 pm Post subject: RE:Help with colour detection please! |
|
|
You would check that every pixel of the object in lower layer is of the colour it is supposed to be. Which is a lot of work.
If the objects are (or could be approximated by) simple shapes (rectangles, ovals, etc.) then there are Math equations to calculate when they collide. You should be able to figure most of those out by sketching the shapes on a piece of paper, and calculating the distance between them. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Insectoid
|
Posted: Fri Nov 27, 2009 4:39 pm Post subject: RE:Help with colour detection please! |
|
|
Typically, color detection is not used. Rather mathematical detection between variables is used. What the screen shows should do NOTHING except provide an interface between user and computer. The only time color detection should be used is when creating bots to control various programs, like the DWITE judge when it tests Turing programs (although I assume that is not the way DWITE works. It probably knows where the Turing window will open and where the 'run' button will be) |
|
|
|
|
|
RathcoM
|
Posted: Fri Nov 27, 2009 5:10 pm Post subject: RE:Help with colour detection please! |
|
|
Thank you for your answers.
The reason i am asking this is because i am trying to create a grid system in my application, so that wherever the object is inside the region a corresponding coordinate such as (a,1) is output. |
|
|
|
|
|
Tony
|
Posted: Fri Nov 27, 2009 5:37 pm Post subject: RE:Help with colour detection please! |
|
|
So then you should check the distance between your object and (a,1). If it's close enough, then that's where it is.
If you are going by colours, then every cell in a grid must have a unique colour, which would probably look quite bad (and you'd need to somehow remember that blue means (a,1)). |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Vermette
|
Posted: Sun Nov 29, 2009 4:28 pm Post subject: RE:Help with colour detection please! |
|
|
The best way to do this would be to have a separate coordinate system for this grid and the objects in it, and write a translation function that maps some grid coordinates into the Component draw coordinates. This way you can keep representation (grid) and presentation (drawpanel) logic separate, and your code will be a lot easier to mess with. |
|
|
|
|
|
|
|