[cairo] Qahirah: A High-Level Cairo API Binding For Python 3
Olaf Schmidt
ng at vbRichClient.com
Tue Mar 10 10:36:19 PDT 2015
Am 10.03.2015 um 01:09 schrieb Lawrence D'Oliveiro:
> I have done enhancements to my alhambra_tiles script to
> demonstrate some of the range of family variation.
> Feel free to keep up.
Ok - let's see...
Your current routine for the ArrowWing-Pattern is about 55 lines.
The selfcontained-routine below (including also PngFile-Output) is:
- significantly less voluminous (only about 35 lines)
- in my opinion easier to understand (math- or construction-wise)
- much easier to port to the flat C-API (straight cairo-default-stuff)
Sub RenderArrowPattern(FileName$, Optional Zoom=1, Optional Tilt=0, _
Optional AFac=1, Optional RFac=1)
Dim R As Double, A As Double, Pat As cCairoPattern
With Cairo.CreateSurface(400, 400).CreateContext
.PushGroup , 0, 0, 48 * Zoom, 48 * Zoom
.ScaleDrawings Zoom, Zoom
.TranslateDrawings 24, 24 'shift into the center of the PushGroup
A = 0.5 * Atn(1) * AFac 'AFac influences the start-angle
R = 12 * RFac 'RFac influences the Radius, RFac=4 equals TileSize
.MoveTo -24, -24 'construct left-part from TopLeft
A = A + 6 * Atn(1): .LineTo R * Cos(A), R * Sin(A)
.LineTo 0, 0
A = A + 6 * Atn(1): .LineTo R * Cos(A), R * Sin(A)
.LineTo -24, 24
.MoveTo 24, 24 'construct right-part from BottomRight
A = A + 6 * Atn(1): .LineTo R * Cos(A), R * Sin(A)
.LineTo 0, 0
A = A + 6 * Atn(1): .LineTo R * Cos(A), R * Sin(A)
.LineTo 24, -24
.FillRule = CAIRO_FILL_RULE_EVEN_ODD
.Fill , Cairo.CreateSolidPatternLng(vbBlack)
Set Pat = .PopGroup(True, CAIRO_EXTEND_REFLECT)
Set Pat.Matrix = Pat.Matrix.RotateCoordsDeg(Tilt)
.Paint , Cairo.CreateSolidPatternLng(vbWhite)
.Paint , Pat
.Surface.WriteContentToPngFile FileName
End With
End Sub
It produces fully "symmetrically reflected" Tile-Parts- and offers
influence over 4 optional Params (Zoom, Tilt, AngleFac, RadiusFac)
Here's some Demo-Output:
'defaults (no Tilt, all Factors as Zoom etc. at 1)
RenderArrowPattern "c:\temp\Arrow1.png"
http://vbRichClient.com/Downloads/Arrow1.png
'Zoom 0.25, Tilt 45°, AngleFactor = 0.6, RadiusFactor = 2.2
RenderArrowPattern "c:\temp\Arrow2.png", 0.25, 45, 0.6, 2.2
http://vbRichClient.com/Downloads/Arrow2.png
'Zoom 1.5, Tilt 45°, AngleFactor = 2, RadiusFactor = 2.5
RenderArrowPattern "c:\temp\Arrow3.png", 1.5, 45, 2, 2.5
http://vbRichClient.com/Downloads/Arrow3.png
'Zoom 2.5, no Tilt, AngleFactor = 4.5, RadiusFactor = 4.5
RenderArrowPattern "c:\temp\Arrow4.png", 2.5, 0, 4.5, 4.5
http://vbRichClient.com/Downloads/Arrow4.png
So, as far as your "keeping up" goes - I'm not really sure
how often we want to repeat the same exercise.
I mean, the extended vector- and matrix-support in your Python-
Wrapper is "nice to have" - but apparently when used for the
"problem at hand", it's (as demonstrated) less efficient code-wise,
compared to "working more near to the original cairo-API with
simple trigonometric math".
Olaf
More information about the cairo
mailing list