To learn how things work in Xlib and XI2 programming, I’ve written a little game. You can attach multiple keyboards to one computer and then invite some friends over to see, who can type fastest. The code is really smelly because I did this only for learning purpose. If you like it, feel free to make the code and/or the game better (like bigger font size or more player support or something).

You can get the code on github.



another screenshot

another screenshot

UPDATE: The code is ported to Qt (better font rendering, fullscreen…) and can be found here: Qt does not support distinguishing key presses between different keyboards, so the event handling code is still X specific.

today I’ve written a program that does this:

input image

output image

Here it is: Source on Github

The input format has to be Portable Gray Map in binary mode (P5) and the output format is Magick Vector Graphic.

Typical usage:
convert yourimage.jpg yourimage.pgm
dotify 5 < yourimage.pgm > yourimage_dotted.mvg
convert yourimage_dotted.mvg yourimage_dotted.jpg

If you have a look at sample.cpp and change the samples-function then you’ll be able to change at which points the dots are placed. Maybe you want to outsource this into a (lua?) script, so you don’t have to recompile on every sampling-method-change or you just want to add further methods to the code and a command line switch to enable them. Feel free to fork me and to send me a merge request.


recently I had to make a website for something. I usually don’t like html code created by tools, so I decided to code that stuff by myself. I couldn’t use PHP or anything like that because of server limitations, but I wanted a header and footer on every page without using iframes, so I wrote this small Makefile.

What it does when you type make: For every .inc file in the directory it creates a .html file, which is just the .inc file with the file header.head in front and the file footer.foot after the content. css files are unaffected.

I hope it is as handy for you as it is for me.

Hello world and welcome to my blog.

Recently I have (inefficiently) implemented an efficient greedy algorithm, which removes those points from a polygon which span up the smallest triangle with their 2 neighbors until the removed triangle would be too large or the vertex count you specified is reached. If you want, you can tell it to only produce convex polygons, as some physic engines need them. This is achieved by not ignoring the sign of the calculated triangle area.

I have added a png reader with libpng to get the base polygon as follows: Use alpha thresholding to differentiate between fore- and background. Then use an edge detector to get the shape and then interpret every pixel on the edge as a polygon vertex. This is way too many vertices, so then the above greedy algorithm comes in handy to reduce the vertex count.

The given code can generate image files (pbm format) showing all vertices or python (py) files that define a variable named “polygon” to contain a list of pairs representing the (x,y) coordinates of each vertex. The former is primarily there for debugging and calibration purpose, the latter is useful if you want to actually use the polygon for something. You can easily alter the code to print the polygon in any other useful format.

Configuration , compilation and execution: Configure the program by opening polymaker.cpp and searching for comments containing the word TWEAK. Compile the program by typing make (the Makefile is very simple, make sure you have libpng dev headers installed). Execute the program with the path to the png file as only argument and forward the standard output to a file of the desired type ( e.g. if you want a pbm with vertices of pic.png do ./polymaker pic.png > polypic.pbm )

Remark: This code is far from being perfect. Known issues:

  • You currently can only make the polygons in clockwise order. This can be easily fixed (look for the according TODOs in polymaker.cpp)
  • Recompiling the polymaker on every configuration change may be unpleasant
  • The program has quadratic runtime although the algorithm could easily have amortized linear runtime in the length of the contour. This is due to a cache for triangle areas missing. If you have pngs large enough to be not processed in an eyeblink no more, this is the place to optimize.
  • The algorithm is a greedy algorithm and delivers quite good, but definitely not optimal results.
  • UPDATE: For some shapes with very sharp edges the tool creates wrong polygons or doesn’t terminate at all due to the rapidly and poorly written shape recognition algorithm

I release this stuff into the Public Domain. Have fun with it!

Download link:

I hope I’ll soon have the time to push this on github or somewhere.

UPDATE: Now it IS on github:
If you like it, you will probably make some changes. Please fork me and send me a pull request. If some people use this tool, it could become more useful over time.

Here you see a small space ship, a convex polygon with 8 vertices and a non-convex polygon with 16 vertices. The lines between the vertices are drawn with GIMP.