Code

Prune initial timer work.
[inkscape.git] / share / extensions / pturtle.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 math
20 class pTurtle:
21     '''A Python path turtle'''
22     def __init__(self, home=(0,0)):
23         self.__home = [home[0], home[1]]
24         self.__pos = self.__home[:]
25         self.__heading = -90
26         self.__path = ""
27         self.__draw = True
28         self.__new = True
29     def forward(self,mag):
30         self.setpos((self.__pos[0] + math.cos(math.radians(self.__heading))*mag,
31             self.__pos[1] + math.sin(math.radians(self.__heading))*mag))
32     def backward(self,mag):
33         self.setpos((self.__pos[0] - math.cos(math.radians(self.__heading))*mag,
34             self.__pos[1] - math.sin(math.radians(self.__heading))*mag))
35     def right(self,deg):
36         self.__heading -= deg
37     def left(self,deg):
38         self.__heading += deg
39     def penup(self):
40         self.__draw = False
41         self.__new = False
42     def pendown(self):
43         if not self.__draw:
44             self.__new = True
45         self.__draw = True
46     def pentoggle(self):
47         if self.__draw:
48             self.penup()
49         else:
50             self.pendown()
51     def home(self):
52         self.setpos(self.__home)
53     def clean(self):
54         self.__path = ''
55     def clear(self):
56         self.clean()
57         self.home()
58     def setpos(self,(x,y)):
59         if self.__new:
60             self.__path += "M"+",".join([str(i) for i in self.__pos])
61             self.__new = False
62         self.__pos = [x, y]
63         if self.__draw:
64             self.__path += "L"+",".join([str(i) for i in self.__pos])
65     def getpos(self):
66         return self.__pos[:]
67     def setheading(self,deg):
68         self.__heading = deg
69     def getheading(self):
70         return self.__heading
71     def sethome(self,(x,y)):
72         self.__home = [x, y]
73     def getPath(self):
74         return self.__path
75     fd = forward
76     bk = backward
77     rt = right
78     lt = left
79     pu = penup
80     pd = pendown
83 # vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99