[cairo] rsvg and colour

Donn donn.ingle at gmail.com
Wed Apr 29 23:02:43 PDT 2009


Well, to keep talking to myself :) I have a partial solution that may help 
someone else in the future:

This is based on my "Things" animation API, the action happens in the draw() 
method:-

class Logo(Thing):
	def __init__(self):
		Thing.__init__(self)
		self.keys(  "#------#", Props(),Props(x=100,y=20))
		self.stops( ".......^")

		self.tint = [0,1,0,1] # r,g,b,a

	def draw(self, ctx, fr):
		# Get a 'pattern' of stuff drawn
		ctx.push_group()
		BOS["CG:logo"].draw(ctx) # an rsvg render
		ctx.set_source_rgb(1,1,0)
		ctx.rectangle(0,0,100,100) # a wee rectangle
		ctx.fill()
		p = ctx.pop_group() # store all that in p

		ctx.set_source(p) # Choose p as the source
		ctx.paint() # Draw it - full-on colour and all

		ctx.set_source_rgba( *self.tint ) # Now make a 'tint'  source.
		ctx.mask(p) #Draw the tint THROUGH the pattern (p is draw again).
		
		self.tint[3] -= 0.1 # Shift the tint down to alpha 0

The idea is that it's drawn twice - the one underneath is gradually revealed 
as the one (tinted green) is drawn with decreasing visibility (alpha gets 
smaller).

It's a bit heavy, but it's what I have figured-out so far.

\d

-- 
Where I web: http://otherwise.relics.co.za/
Comics, tutorials, software and sundry


More information about the cairo mailing list