Code

Translations. French translation minor update.
[inkscape.git] / share / extensions / rtree.py
1 #!/usr/bin/env python 
2 '''
3 Copyright (C) 2005 Aaron Spike, aaron@ekips.org
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 '''
19 import inkex, simplestyle, pturtle, random
21 def rtree(turtle, size, min):
22     if size < min:
23         return
24     turtle.fd(size)
25     turn = random.uniform(20, 40)
26     turtle.lt(turn)
27     rtree(turtle, size*random.uniform(0.5,0.9), min)
28     turtle.rt(turn)
29     turn = random.uniform(20, 40)
30     turtle.rt(turn)
31     rtree(turtle, size*random.uniform(0.5,0.9), min)
32     turtle.lt(turn)
33     turtle.bk(size)
35 class RTreeTurtle(inkex.Effect):
36     def __init__(self):
37         inkex.Effect.__init__(self)
38         self.OptionParser.add_option("-s", "--size",
39                         action="store", type="float", 
40                         dest="size", default=100.0,
41                         help="initial branch size")
42         self.OptionParser.add_option("-m", "--minimum",
43                         action="store", type="float", 
44                         dest="minimum", default=4.0,
45                         help="minimum branch size")
46     def effect(self):
47         s = {'stroke-linejoin': 'miter', 'stroke-width': '1.0px', 
48             'stroke-opacity': '1.0', 'fill-opacity': '1.0', 
49             'stroke': '#000000', 'stroke-linecap': 'butt', 
50             'fill': 'none'}
51         t = pturtle.pTurtle()
52         t.pu()
53         t.setpos(self.view_center)
54         t.pd()
55         rtree(t, self.options.size, self.options.minimum)
56         
57         attribs = {'d':t.getPath(),'style':simplestyle.formatStyle(s)}
58         inkex.etree.SubElement(self.current_layer, inkex.addNS('path','svg'), attribs)
60 if __name__ == '__main__':
61     e = RTreeTurtle()
62     e.affect()
65 # vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99