[READ-ONLY] Mirror of https://github.com/thoda-dev/svg-lua. svg lua library
0

Configure Feed

Select the types of activity you want to include in your feed.

added Ellipse support

Thomas DAGES (Dec 6, 2018, 4:44 PM +0100) 89e26ab6 24d64020

+29 -8
+6 -6
README.md
··· 8 8 mon_dessin:draw() 9 9 ``` 10 10 11 - result for `print(mon_dessin:draw)` : 11 + result for `print(mon_dessin:draw())` : 12 12 ```html 13 13 <svg width="100" height="100" fill="transparent" stroke="#000000" version="1.1" xmlns="http://www.w3.org/2000/svg"> 14 14 <rect y="10" x="10" stroke-width="1" height="10" width="10" rx="0" ry="0" /> ··· 37 37 38 38 **svg:draw()** *return the svg formated string* 39 39 40 - ### Elements for svg:add() 40 + ### Elements for svg:add(element) 41 41 **svg:Rect(x, y, width, height, stroke, strokeWidth, fill, rx, ry)** *add a rectangle* 42 42 43 43 - x: number => Horizontal position from top left corner, default to 10 44 44 - y: number => Vertical position from top left corner, default to 10 45 45 - width: number => Width of the rectangle, default to 10 46 46 - height: number => Height of the rectangle, default to 10 47 - - stroke: string => lines color, default to svg:create() parameter *("#000000")* 47 + - stroke: string => lines color, default to svg:create() parameter ("#000000" by default) 48 48 - strokeWidth: string => lines width, default to 1 49 - - fill: string => fill color, default to svg:create() parameter *("transparent")* 49 + - fill: string => fill color, default to svg:create() parameter ("transparent" by default) 50 50 - rx: number => Horizontal raduis of the corners, default to 0 51 51 - ry: number => Vertical radius of the corners, default to 0 52 52 ··· 55 55 - r: number => circle radius, default to 25 56 56 - cx: number => Horizontal position of the center, default to 30 57 57 - cy: number => Vertical position of the center, default to 30 58 - - stroke: string => lines color, default to svg:create() parameter *("#000000")* 58 + - stroke: string => lines color, default to svg:create() parameter ("#000000" by default) 59 59 - strokeWidth: string => lines width, default to 1 60 - - fill: string => fill color, default to svg:create() parameter *("transparent")* 60 + - fill: string => fill color, default to svg:create() parameter ("transparent" by default)
+20
svg.lua
··· 96 96 ["stroke-width"] = strokeWidth or 1, 97 97 fill = fill or self.fill 98 98 }) 99 + end 100 + 101 + -- function to create an ellipse 102 + -- cx: number => Horizontal position of the center 103 + -- cy: number => Vertical position of the center 104 + -- rx: number => Horizontal radius of the ellipse 105 + -- ry: number => Vertical radius of the ellipse 106 + -- stroke: string => lines color 107 + -- strokeWidth: string => lines width 108 + -- fill: string => fill color 109 + function svg:Ellipse(cx, cy, rx, ry, stroke, strokeWidth, fill) 110 + return self.Element:create("ellipse", { 111 + rx = r or 25, 112 + ry = r or 15, 113 + cx = cx or 30, 114 + cy = cy or 30, 115 + stroke = stroke or self.stroke, 116 + ["stroke-width"] = strokeWidth or 1, 117 + fill = fill or self.fill 118 + }) 99 119 end
+1 -1
svg.min.lua
··· 1 - 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 1 + 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
··· 1 - 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 1 + 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 2 3 3 mon_dessin = svg:create() 4 4 mon_dessin:add(mon_dessin:Rect()) 5 5 mon_dessin:add(mon_dessin:Circle()) 6 + mon_dessin:add(mon_dessin:Ellipse()) 6 7 print(mon_dessin:draw())