Voronoi Diagram

Here’s another imaging example done with PHP – a Voronoi Diagram. I don’t exactly remember when I wrote this, but it was some time this year. The code doesn’t use any fancy, ultra-efficient algorithm, so it takes several seconds to make a medium-size image on my (old) computer.

The algorithm used is very simple: Iterate through each pixel of the image, and find which reference point it is closest to. Then, set the color of the pixel to the color of the reference point.

Here’s the code.

Voronoi Diagram

Voronoi Diagram with 50 Colors

This entry was posted in PHP and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>