PageRenderTime 24ms CodeModel.GetById 19ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/static/june_2007_style/circle.py

https://bitbucket.org/h_morita_dbcls/galaxy-central
Python | 55 lines | 36 code | 15 blank | 4 comment | 3 complexity | afd2a18b492ebe15ed429ac36df08387 MD5 | raw file
 1#!/usr/bin/env python
 2
 3"""
 4usage: %prog width height bg_color hatch_color [color alpha stop_pos] +
 5"""
 6
 7from __future__ import division
 8
 9import sys
10import cairo
11from math import pi
12
13assert sys.version_info[:2] >= ( 2, 4 )
14
15def parse_css_color( color ):
16    if color.startswith( '#' ):
17        color = color[1:]
18    if len( color ) == 3:
19        r = int( color[0], 16 )
20        g = int( color[1], 16 )
21        b = int( color[2], 16 )
22    elif len( color ) == 6:
23        r = int( color[0:2], 16 )
24        g = int( color[2:4], 16 )
25        b = int( color[4:6], 16 )
26    else:
27        raise Exception( "Color should be 3 hex numbers" )
28    return r/256, g/256, b/256
29                        
30size = int( sys.argv[1] )
31
32    
33surface = cairo.ImageSurface( cairo.FORMAT_ARGB32, size, size )
34c = cairo.Context( surface )
35
36c.set_line_width( 1 )
37
38c.arc( size / 2.0, size / 2.0, ( size - 1 ) / 2.0, 0, 2 * pi )
39
40c.set_source_rgb( *parse_css_color( sys.argv[2] ) )
41c.fill_preserve()
42
43c.set_source_rgb( *parse_css_color( sys.argv[3] ) )
44c.stroke()
45
46t = size / 4.0
47
48arrow = sys.argv[4]
49if arrow == 'right':
50    c.move_to( t + 1, t )
51    c.line_to( 3*t - 1, 2*t )
52    c.line_to( t + 1, 3*t )
53    c.stroke()
54
55surface.write_to_png( "/dev/stdout" )