···25252626 - width: number => width of the drawing, default to 100
2727 - height: number => height of the drawing, default to 100
2828- - stroke: string => lines color, default to '#000000'
2929- - fill: string => fill color, default to 'transparent'
2828+ - stroke: string => lines color, default to "#000000"
2929+ - fill: string => fill color, default to "transparent"
30303131**svg:add(element)** *add an element to the drawing*
3232···3535**svg:draw()** *return the svg formated string*
36363737### Elements for svg:add()
3838-**svg:Rect()** *add a rectangle*
3838+**svg:Rect(x, y, width, height, stroke, strokeWidth, fill, rx, ry)** *add a rectangle*
39394040 - x: number => Horizontal position from top left corner, default to 10
4141 - y: number => Vertical position from top left corner, default to 10
4242 - width: number => Width of the rectangle, default to 10
4343 - height: number => Height of the rectangle, default to 10
4444- - stroke: string => lines color, default to '#000000'
4444+ - stroke: string => lines color, default to svg:create() parameter *("#000000")*
4545 - strokeWidth: string => lines width, default to 1
4646- - fill: string => fill color, default to transparent
4646+ - fill: string => fill color, default to svg:create() parameter *("transparent")*
4747 - rx: number => Horizontal raduis of the corners, default to 0
4848- - ry: number => Vertical radius of the corners, default to 04848+ - ry: number => Vertical radius of the corners, default to 0
4949+5050+**svg:Circle(r, cx, cy, stroke, strokeWidth, fill)** *add a circle*
5151+5252+ - r: number => circle radius, default to 25
5353+ - cx: number => Horizontal position of the center, default to 30
5454+ - cy: number => Vertical position of the center, default to 30
5555+ - stroke: string => lines color, default to svg:create() parameter *("#000000")*
5656+ - strokeWidth: string => lines width, default to 1
5757+ - fill: string => fill color, default to svg:create() parameter *("transparent")*
+18
svg.lua
···7878 rx = rx or 0,
7979 ry = ry or 0
8080 })
8181+end
8282+8383+-- function to create a circle
8484+-- r: number => circle radius
8585+-- cx: number => Horizontal position of the center
8686+-- cy: number => Vertical position of the center
8787+-- stroke: string => lines color
8888+-- strokeWidth: string => lines width
8989+-- fill: string => fill color
9090+function svg:Circle(r, cx, cy, stroke, strokeWidth, fill)
9191+ return self.Element.create("circle", {
9292+ r = r or 25,
9393+ cx = cx or 30,
9494+ cy = cy or 30,
9595+ stroke = stroke or self.stroke,
9696+ ["stroke-width"] = strokeWidth or 1,
9797+ fill = fill or self.fill
9898+ })
8199end
+1-1
svg.min.lua
···11-svg={}svg.__index=svg;function svg:create(a,b,c,d)local e={}setmetatable(e,svg)e.width=a or 100;e.height=height or 100;e.stroke=c or"#000000"e.fill=d or"transparent"e.elements={}e.Element={}e.Element.__index=svg.Element;function e.Element:create(f,g)local h={}setmetatable(h,e.Element)h.name=f;h.strElement="<"..f.." "for i,j in pairs(g)do h[i]=j;h.strElement=h.strElement..i.."=\""..j.."\" "end;h.strElement=h.strElement.."/>"return h end;return e end;function svg:add(k)table.insert(self.elements,k)end;function svg:draw()local l="<svg width=\""..self.width.."\" height=\""..self.height.."\" fill=\""..self.fill.."\" stroke=\""..self.stroke.."\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">"for m,n in pairs(self.elements)do l=l..n.strElement end;l=l.."</svg>"return l end;function svg:Rect(o,p,a,height,c,q,d,r,s)return self.Element:create("rect",{x=o or 10,y=p or 10,width=a or 10,height=height or 10,stroke=c or self.stroke,fill=d or self.fill,["stroke-width"]=q or 1,rx=r or 0,ry=s or 0})end11+svg={}svg.__index=svg;function svg:create(a,b,c,d)local e={}setmetatable(e,svg)e.width=a or 100;e.height=height or 100;e.stroke=c or"#000000"e.fill=d or"transparent"e.elements={}e.Element={}e.Element.__index=svg.Element;function e.Element:create(f,g)local h={}setmetatable(h,e.Element)h.name=f;h.strElement="<"..f.." "for i,j in pairs(g)do h[i]=j;h.strElement=h.strElement..i.."=\""..j.."\" "end;h.strElement=h.strElement.."/>"return h end;return e end;function svg:add(k)table.insert(self.elements,k)end;function svg:draw()local l="<svg width=\""..self.width.."\" height=\""..self.height.."\" fill=\""..self.fill.."\" stroke=\""..self.stroke.."\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">"for m,n in pairs(self.elements)do l=l..n.strElement end;l=l.."</svg>"return l end;function svg:Rect(o,p,a,height,c,q,d,r,s)return self.Element:create("rect",{x=o or 10,y=p or 10,width=a or 10,height=height or 10,stroke=c or self.stroke,fill=d or self.fill,["stroke-width"]=q or 1,rx=r or 0,ry=s or 0})end;function svg:Circle(t,u,v,c,q,d)return self.Element.create("circle",{r=t or 25,cx=u or 30,cy=v or 30,stroke=c or self.stroke,["stroke-width"]=q or 1,fill=d or self.fill})end