···88mon_dessin:draw()
99```
10101111-result for `print(mon_dessin:draw)` :
1111+result for `print(mon_dessin:draw())` :
1212```html
1313<svg width="100" height="100" fill="transparent" stroke="#000000" version="1.1" xmlns="http://www.w3.org/2000/svg">
1414 <rect y="10" x="10" stroke-width="1" height="10" width="10" rx="0" ry="0" />
···37373838**svg:draw()** *return the svg formated string*
39394040-### Elements for svg:add()
4040+### Elements for svg:add(element)
4141**svg:Rect(x, y, width, height, stroke, strokeWidth, fill, rx, ry)** *add a rectangle*
42424343 - x: number => Horizontal position from top left corner, default to 10
4444 - y: number => Vertical position from top left corner, default to 10
4545 - width: number => Width of the rectangle, default to 10
4646 - height: number => Height of the rectangle, default to 10
4747- - stroke: string => lines color, default to svg:create() parameter *("#000000")*
4747+ - stroke: string => lines color, default to svg:create() parameter ("#000000" by default)
4848 - strokeWidth: string => lines width, default to 1
4949- - fill: string => fill color, default to svg:create() parameter *("transparent")*
4949+ - fill: string => fill color, default to svg:create() parameter ("transparent" by default)
5050 - rx: number => Horizontal raduis of the corners, default to 0
5151 - ry: number => Vertical radius of the corners, default to 0
5252···5555 - r: number => circle radius, default to 25
5656 - cx: number => Horizontal position of the center, default to 30
5757 - cy: number => Vertical position of the center, default to 30
5858- - stroke: string => lines color, default to svg:create() parameter *("#000000")*
5858+ - stroke: string => lines color, default to svg:create() parameter ("#000000" by default)
5959 - strokeWidth: string => lines width, default to 1
6060- - fill: string => fill color, default to svg:create() parameter *("transparent")*6060+ - fill: string => fill color, default to svg:create() parameter ("transparent" by default)
+20
svg.lua
···9696 ["stroke-width"] = strokeWidth or 1,
9797 fill = fill or self.fill
9898 })
9999+end
100100+101101+-- function to create an ellipse
102102+-- cx: number => Horizontal position of the center
103103+-- cy: number => Vertical position of the center
104104+-- rx: number => Horizontal radius of the ellipse
105105+-- ry: number => Vertical radius of the ellipse
106106+-- stroke: string => lines color
107107+-- strokeWidth: string => lines width
108108+-- fill: string => fill color
109109+function svg:Ellipse(cx, cy, rx, ry, stroke, strokeWidth, fill)
110110+ return self.Element:create("ellipse", {
111111+ rx = r or 25,
112112+ ry = r or 15,
113113+ cx = cx or 30,
114114+ cy = cy or 30,
115115+ stroke = stroke or self.stroke,
116116+ ["stroke-width"] = strokeWidth or 1,
117117+ fill = fill or self.fill
118118+ })
99119end
+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})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})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,s,t)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=s or 0,ry=t or 0})end;function svg:Circle(r,u,v,c,q,d)return self.Element:create("circle",{r=r 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;function svg:Ellipse(u,v,s,t,c,q,d)return self.Element:create("ellipse",{rx=r or 25,ry=r or 15,cx=u or 30,cy=v or 30,stroke=c or self.stroke,["stroke-width"]=q or 1,fill=d or self.fill})end
+2-1
test.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})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
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,s,t)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=s or 0,ry=t or 0})end;function svg:Circle(r,u,v,c,q,d)return self.Element:create("circle",{r=r 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;function svg:Ellipse(u,v,s,t,c,q,d)return self.Element:create("ellipse",{rx=r or 25,ry=r or 15,cx=u or 30,cy=v or 30,stroke=c or self.stroke,["stroke-width"]=q or 1,fill=d or self.fill})end
2233mon_dessin = svg:create()
44mon_dessin:add(mon_dessin:Rect())
55mon_dessin:add(mon_dessin:Circle())
66+mon_dessin:add(mon_dessin:Ellipse())
67print(mon_dessin:draw())