Python and Cairo – There will be blood…
As I was thrilled about the movie- “there will be blood”, I decided to create a simple GTK animation which shows the spreading of blood in the floor.. obviously insipired from the name of the movie
Python code
#########################################################################
#
#PyCairo Demo:- There will be blood ..
#By Maxin B. John
#An animation to show the capabilites of PyCairo
#
# About Cairo
# Cairo is a software library used to provide a vector graphics based,
# device-independent API for software developers. It is designed to provide
# primitives for 2-dimensional drawing across a number of different backends.
#Cairo is designed to use hardware acceleration when available.
# #########################################################################
#!/usr/bin/env python
import sys
import gobject
import pygtk
pygtk.require(’2.0′)
import gtk
from gtk import gdk
import cairo
if gtk.pygtk_version < (2,10,0):
print “PyGtk 2.10.0 or later required”
raise SystemExit
win = None
#The blood is a circle filled with red color whose radius grows with time
def expose(widget, event):
global radius
cr= widget.window.cairo_create()
cr.set_source_rgba(1.0, 0, 0, 0.7)
cr.arc(float(radius)/2, float(radius)/2, radius, 0, 2.0*3.14)
cr.fill()
cr.stroke()
return True
# this keeps the blood flowing…
def update_clock():
global win
global radius
radius = radius +1
win.queue_draw()
return True
# the ‘main’ function
def main(args):
global win
global radius
radius =0
win = gtk.Window()
win.set_app_paintable(True)
win.set_title(‘PyCairo Demo’)
win.connect(‘delete-event’, gtk.main_quit)
win.connect(‘expose-event’, expose)
gobject.timeout_add(100, update_clock)
win.show_all()
gtk.main()
return True
# The pythonic way to start the animation
if __name__ == ‘__main__’:
sys.exit(main(sys.argv))
And the output 

Don’t you feel the smell of blood… ???