RMagick and Collision Mask

Im trying to make a perfect pixel collision in a game and im gonna use a
collision mask to do this, the physics its with chipmunk and i need a
polygon to do it, my idea is, read the image pixel per pixel and store
in a matrix the x and y of the black pixels, later with this matrix i
can create a poligon just geting the first and last element from the
column in each line of the matrix.

The problem is the RMagick, i know how to read the image pixel per pixel
but dont know how to compare the color to get only the black pixels

Someone can help me?

thx :slight_smile:

Diego B. wrote:

Im trying to make a perfect pixel collision in a game and im gonna use a
collision mask to do this, the physics its with chipmunk and i need a
polygon to do it, my idea is, read the image pixel per pixel and store
in a matrix the x and y of the black pixels, later with this matrix i
can create a poligon just geting the first and last element from the
column in each line of the matrix.

The problem is the RMagick, i know how to read the image pixel per pixel
but dont know how to compare the color to get only the black pixels

Someone can help me?

thx :slight_smile:

black = Magick::Pixel.from_color(“black”)
p == black # true if the pixel p is black.

If you want to include “almost black” pixels then use
Magick::Pixel#fcmp:
http://www.imagemagick.org/RMagick/doc/struct.html#Pixel.

If you have any other questions about RMagick you can always contact me
at [email protected], or post your question on the Help Forum for
the RMagick project on RubyForge:
http://rubyforge.org/forum/?group_id=12.