Drawing a chess board with Ruby and Cairo
So I spent the evening hacking together this little app to draw a standard chess board with some 32×32 chess piece icons from IconBuffet. Sadly, ruby-gnome2 ’s documentation is lacking with respect to Cairo, so I had to switch between using reflection to examine the instance methods of various Cairo classes and their respective C documentation. Since the results are immediate, graphics programming is usually fun. But for the first couple hours I was stumped on a handful of code that was merely supposed to draw a single line and a PNG. The app either drew nothing at all, or painted the entire surface black. I eventually traced the errors to an unnecessary scaling function call that caused things to be drawn much, much larger than normal in a clipped region. So trying to rationalize the app’s odd behavior was like driving while wearing binoculars. Nevertheless, Cairo is cleanly designed and powerful. I look forward to messing around with it some more.
Next up is refactoring this simple do-nothing app into a full-fledged widget and by then I’ll have a good enough grasp of the differences between Cairo’s Ruby bindings and the C API to rewrite Davyd Madeley’s excellent GNOME Journal articles on writing Cairo-based GTK widgets (of which there already exists Pythonized versions).



0 Comments:
Post a Comment
<< Home