RMagick and Collision Mask

  • Thread starter Diego Bernardes
  • Start date
D

Diego Bernardes

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 :)
 
T

Tim Hunter

Diego said:
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 :)

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 (e-mail address removed), or post your question on the Help Forum for
the RMagick project on RubyForge:
http://rubyforge.org/forum/?group_id=12.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

[ANN] RMagick 2.3.0 10
RMagick and circle problem 1
RMagick 1.15.14 0
rmagick question 16
problem with image rotate RMagick 2
Collision map 2
SVG not full width and space 0
[ANN] RMagick 2.3.0 for Windows 0

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top