rendered paste body#! /usr/bin/env pythonimport cairofrom math import piimport sysimport timescl=0.95#scl=0.99425220665277636iter=250#xdp=-200#angle = 2angle=0xdp=-15if len(sys.argv) == 2: fct=float(sys.argv[1])*10 angle *= fct xdp *= fctprint "Setup:",time.clock()iw, ih = iwidth, iheight = 1165,1165#surface = cairo.SVGSurface("thx.svg",iwidth, iheight)surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,iwidth, iheight)cr = cairo.Context(surface)width, height = w,h = 1000,1000cr.scale(float(iw) / w, float(ih)/h)# Fill in the backgroundcr.set_source_rgb(1,1,1)cr.paint()fopt = cairo.FontOptions()fopt.set_hint_metrics(cairo.HINT_METRICS_OFF)fopt.set_hint_style(cairo.HINT_STYLE_NONE)def mkthx(cr): # Paint a thankyou centered at the current coordinates cr.save() cr.set_source_rgb(0,0,0) cr.select_font_face("Courier 10 Pitch") cr.set_font_options(fopt) txt = "Thank you" xb, yb, tw, th, xtr, ytr = cr.text_extents(txt) cr.move_to(-xtr/2, -ytr/2) cr.text_path(txt) cr.fill() cr.restore()# Move to image centercr.translate(w/2., h/2.)# And paint a heartmkthx(cr)class iterfactory: def __init__(self, surface, angle, xdp, ydp, scl, iterf): self.surface,self.angle,self.xdp,self.ydp,self.scl=surface,angle,xdp,ydp,scl self.iterf = iterf self.cr = cairo.Context(self.surface) self.cr.scale(float(iw)/w, float(ih)/h) self.cr.translate(w/2., h/2.) def iterate(self): self.cr.translate(self.xdp, self.ydp) self.cr.rotate(pi / 180 * self.angle) self.cr.scale(self.scl, self.scl) self.iterf(self.cr)print "Begin iterate:", time.clock()factories = [ #iterfactory(surface, angle, xdp, 0, scl, mkthx), #iterfactory(surface, angle, -xdp, 0, scl, mkthx), iterfactory(surface, angle, 0, xdp, scl, mkthx), iterfactory(surface, angle, 0, -xdp, scl, mkthx) ] for i in range(iter): for f in factories: f.iterate()print "Commence output:", time.clock()surface.write_to_png("thx.png")print "Complete:", time.clock()