1 from pysvg import *
3 """
4 Helper class that creates commonly used objects and shapes with predefined styles and
5 few but often used parameters. Used to avoid more complex coding for common tasks.
6 """
7 - def createCircle(self, cx, cy, r, strokewidth=1, stroke='black', fill='none'):
8 """
9 Creates a circle
10 @type cx: string or int
11 @param cx: starting x-coordinate
12 @type cy: string or int
13 @param cy: starting y-coordinate
14 @type r: string or int
15 @param r: radius
16 @type strokewidth: string or int
17 @param strokewidth: width of the pen used to draw
18 @type stroke: string (either css constants like "black" or numerical values like "#FFFFFF")
19 @param stroke: color with which to draw the outer limits
20 @type fill: string (either css constants like "black" or numerical values like "#FFFFFF")
21 @param fill: color with which to fill the element (default: no filling)
22 @return: a circle object
23 """
24 style_dict={'fill':fill,'stroke-width':strokewidth,'stroke':stroke}
25 return circle(cx,cy,r,style_dict)
26
27 - def createEllipse(self, cx, cy, rx, ry, strokewidth=1, stroke='black', fill='none'):
28 """
29 Creates an ellipse
30 @type cx: string or int
31 @param cx: starting x-coordinate
32 @type cy: string or int
33 @param cy: starting y-coordinate
34 @type rx: string or int
35 @param rx: radius in x direction
36 @type ry: string or int
37 @param ry: radius in y direction
38 @type strokewidth: string or int
39 @param strokewidth: width of the pen used to draw
40 @type stroke: string (either css constants like "black" or numerical values like "#FFFFFF")
41 @param stroke: color with which to draw the outer limits
42 @type fill: string (either css constants like "black" or numerical values like "#FFFFFF")
43 @param fill: color with which to fill the element (default: no filling)
44 @return: an ellipse object
45 """
46 style_dict={'fill':fill,'stroke-width':strokewidth,'stroke':stroke}
47 return ellipse(cx,cy,rx,ry,style_dict)
48
49 - def createRect(self, x, y, width, height, rx=None, ry=None, strokewidth=1, stroke='black', fill='none'):
50 """
51 Creates a Rectangle
52 @type x: string or int
53 @param x: starting x-coordinate
54 @type y: string or int
55 @param y: starting y-coordinate
56 @type width: string or int
57 @param width: width of the rectangle
58 @type height: string or int
59 @param height: height of the rectangle
60 @type rx: string or int
61 @param rx: For rounded rectangles, the x-axis radius of the ellipse used to round off the corners of the rectangle.
62 @type ry: string or int
63 @param ry: For rounded rectangles, the y-axis radius of the ellipse used to round off the corners of the rectangle.
64 @type strokewidth: string or int
65 @param strokewidth: width of the pen used to draw
66 @type stroke: string (either css constants like "black" or numerical values like "#FFFFFF")
67 @param stroke: color with which to draw the outer limits
68 @type fill: string (either css constants like "black" or numerical values like "#FFFFFF")
69 @param fill: color with which to fill the element (default: no filling)
70 @return: a rect object
71 """
72 style_dict={'fill':fill,'stroke-width':strokewidth,'stroke':stroke}
73 return rect(x,y,width,height,rx,ry,style_dict)
74
75 - def createPolygon(self, points, strokewidth=1, stroke='black', fill='none'):
76 """
77 Creates a Polygon
78 @type points: string in the form "x1,y1 x2,y2 x3,y3"
79 @param points: all points relevant to the polygon
80 @type strokewidth: string or int
81 @param strokewidth: width of the pen used to draw
82 @type stroke: string (either css constants like "black" or numerical values like "#FFFFFF")
83 @param stroke: color with which to draw the outer limits
84 @type fill: string (either css constants like "black" or numerical values like "#FFFFFF")
85 @param fill: color with which to fill the element (default: no filling)
86 @return: a polygon object
87 """
88 style_dict={'fill':fill,'stroke-width':strokewidth,'stroke':stroke}
89 return polygon(points=points,style_dict=style_dict)
90
92 """
93 Creates a Polyline
94 @type points: string in the form "x1,y1 x2,y2 x3,y3"
95 @param points: all points relevant to the polygon
96 @type strokewidth: string or int
97 @param strokewidth: width of the pen used to draw
98 @type stroke: string (either css constants like "black" or numerical values like "#FFFFFF")
99 @param stroke: color with which to draw the outer limits
100 @return: a polyline object
101 """
102 style_dict={'fill':'none','stroke-width':strokewidth,'stroke':stroke}
103 return polyline(points=points,style_dict=style_dict)
104
105
106 - def createLine(self,x1,y1,x2,y2,strokewidth=1,stroke="black"):
107 """
108 Creates a line
109 @type x1: string or int
110 @param x1: starting x-coordinate
111 @type x1: string or int
112 @param y1: starting y-coordinate
113 @type y2: string or int
114 @param x2: ending x-coordinate
115 @type y2: string or int
116 @param y2: ending y-coordinate
117 @type strokewidth: string or int
118 @param strokewidth: width of the pen used to draw
119 @type stroke: string (either css constants like "black" or numerical values like "#FFFFFF")
120 @param stroke: color with which to draw the outer limits
121 @return: a line object
122 """
123 style_dict={'stroke-width':strokewidth,'stroke':stroke}
124 return line(x1,y1,x2,y2,style_dict)
125
127 """Method used to convert an array of tuples (x,y) into a string
128 suitable for createPolygon or createPolyline
129 @type arrayOfPointTuples: An array containing tuples eg.[(x1,y1),(x2,y2]
130 @param arrayOfPointTuples: All points needed to create the shape
131 @return a string in the form "x1,y1 x2,y2 x3,y3"
132 """
133 points=""
134 for tuple in arrayOfPointTuples:
135 points+=tuple[0]+","+tuple[1]+" "
136