[cairo] Qahirah: A High-Level Cairo API Binding For Python 3

Olaf Schmidt ng at vbRichClient.com
Tue Mar 10 23:13:48 PDT 2015


Am 11.03.2015 um 00:08 schrieb Lawrence D'Oliveiro:

> All that effort, and you still cannot display more than one instance
> of one pattern at one time.

<sigh>
These were standalone-functions, which produced different
output-variants over appropriate parameters...

But since you insist - here you can look at the entire VB6-Form-Code...
http://vbRichClient.com/Downloads/AlhambraTiles_FormCode.txt

...which produced the following Window-Content:
http://vbRichClient.com/Downloads/AlhambraTiles_Screenshot.png

...along with the following Cairo-PNG-Output:
http://vbRichClient.com/Downloads/AlhambraTiles_CairoOutput.png

> And I notice you have dropped any mention of the second, “arrowing” pattern.

I've already shown a routine which produced asymmetric TriWing-Patterns,
(which looked quite nice too) - but as you see in the above Images,
a symmetric TriWing-Output is of course also possible - with a
comparable amount of LOC.

> Is all this getting too complex for you?

Well, first you complain about "content-free hand-waving" (in a
quite arrogant manner), then - when somebody "delivers" (and points
out inefficiencies in your Python-Coding), you resort to name-calling.

Not really great sportsmanship, I might add...

> Do yourself a favour: if you are trying to show up deficiencies in
> Python, don’t do it with Microsoft Visual Basic.

Well, as I already pointed out - and as is clearly observable when
you really look at the routines - the VB-Glue-Code (which makes use
of COM-based cairo-wrapper-Classes) is not all that different from
"straight cairo-API-usage".

So, language was (at least for me) a secondary point in the whole
exercise.

And I wasn't trying "to show up deficiencies in Python" (generally) -
just pointing out inefficient (overcomplicated, if you like that better)
coding of your Tile-Pattern-generator-routines.

As for your language-bashing-attempt - it's quite immature you know,
when developers try to define themselves over their "choice of
glue-code-lingo".

It's libraries and bindings which count (and how deeply you understand
those libs and their API) - and my advice was offered in that sense -
but feel free to ignore it further.

Anyways, the facts are, that the VB6-Code in the link above:
- has about factor 2.5 less lines of code than your Python-based
   Alhambra-Routines at:
   https://github.com/ldo/qahirah_examples/blob/master/alhambra_tiles
- is able to produce all kind of variations of the two patterns as well
- is more near the cairo-base-API (and thus nearly 1:1 portable to C)
- works reliable!

The last point above I've made, since your latest Alhambra-Tiles-
Revision is producing artefacts with certain angle-arguments...
Here's the PNG-output, your revised Python-code produced:
http://vbRichClient.com/Downloads/alhambra_tiles2.py.png
...please have a look at the two last images in the Top-Row.

Here's the parameter-set for the TriWing, I've used:
triwing_params = \
     [
         {"curve_factor" : 0.7, "tilt" : 30 * deg},
         {"curve_factor" : 0.9, "tilt" : 25 * deg},
         {"curve_factor" : 0.9, "tilt" : -25 * deg},
     ]

The artefact is produced for the negative angle (-25 * deg).

What I've also noticed (I'm mentioning it only, since you didn't
label your wrapper as "experimental") ... it broke existing code -
meaning, that your older alhambra.py-example doesn't work with
your latest quahira.py anymore - here's what I get when I try to run it:

c:\Python34>python alhambra_tiles.py
Traceback (most recent call last):
   File "alhambra_tiles.py", line 76, in <module>
     dimensions = triwing_pattern_dimensions * pattern_res
   File "c:\Python34\lib\qahirah.py", line 2829, in create
     ImageSurface(cairo.cairo_image_surface_create(format, dimensions.x, 
dimensions.y))
ctypes.ArgumentError: argument 2: <class 'TypeError'>: wrong type

Don't know, if that's the first binding you wrote - but as soon as
you declare it ready - and encourage users to base their own stuff
on it, you should try to avoid such breaking changes in the future.

Regards,

Olaf




More information about the cairo mailing list