[READ-ONLY] Mirror of https://github.com/thoda-dev/svg-lua. svg lua library
Something went wrong. Try again.
12svg={}svg.__index=svg;function svg:create(a,b,c,d)local e={}setmetatable(e,svg)e.width=a or 100;e.height=b 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,h)local i={}setmetatable(i,e.Element)i.name=f;i.strElement="<"..f.." "for j,k in pairs(g)do i[j]=k;i.strElement=i.strElement..j.."=\""..k.."\" "end;if h~=nil then i.strElement=i.strElement..">"..h.."</"..f..">"else i.strElement=i.strElement.."/>"end;return i end;return e end;function svg:add(l)table.insert(self.elements,l)end;function svg:draw()local m="<svg width=\""..self.width.."\" height=\""..self.height.."\" fill=\""..self.fill.."\" stroke=\""..self.stroke.."\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">"for n,o in pairs(self.elements)do m=m..o.strElement end;m=m.."</svg>"return m end;function svg:innerdraw()local m=""for n,o in pairs(self.elements)do m=m..o.strElement end;return m end;function svg:Text(p,q,r,s,t,u)local g={x=q or 0,y=r or 0}if not(s==nil)and not(s=="")then g["text-anchor"]=s end;if not(t==nil)and not(t=="")then g.style=t end;if not(u==nil)and not(u=="")then g.transform=u end;return self.Element:create("text",g,p)end;function svg:addText(p,q,r,s,t,u)self:add(self:Text(p,q,r,s,t,u))end;function svg:Rect(q,r,a,b,c,v,d,w,x,u)local g={x=q or 0,y=r or 0,width=a or 20,height=b or 10}if not(c==nil)and not(c=="")then g.stroke=c end;if not(d==nil)and not(d=="")then g.fill=d end;if not(v==nil)and not(v=="")then g["stroke-width"]=v end;if not(w==nil)and not(w=="")then g.rx=w end;if not(x==nil)and not(x=="")then g.ry=x end;if not(u==nil)and not(u=="")then g.transform=u end;return self.Element:create("rect",g)end;function svg:addRect(q,r,a,b,c,v,d,w,x,u)self:add(self:Rect(q,r,a,b,c,v,d,w,x,u))end;function svg:Circle(y,z,A,c,v,d,u)local g={r=y or 25,cx=z or 30,cy=A or 30}if not(c==nil)and not(c=="")then g.stroke=c end;if not(v==nil)and not(v=="")then g["stroke-width"]=v end;if not(d==nil)and not(d=="")then g.fill=d end;if not(u==nil)and not(u=="")then g.transform=u end;return self.Element:create("circle",g)end;function svg:addCircle(y,z,A,c,v,d,u)self:add(self:Circle(y,z,A,c,v,d,u))end;function svg:Ellipse(z,A,w,x,c,v,d,u)local g={rx=w or 25,ry=x or 15,cx=z or 30,cy=A or 30}if not(c==nil)and not(c=="")then g.stroke=c end;if not(v==nil)and not(v=="")then g["stroke-width"]=v end;if not(d==nil)and not(d=="")then g.fill=d end;if not(u==nil)and not(u=="")then g.transform=u end;return self.Element:create("ellipse",g)end;function svg:addEllipse(z,A,w,x,c,v,d,u)self:add(self:Ellipse(z,A,w,x,c,v,d,u))end;function svg:Line(B,C,D,E,c,v,d)local g={x1=B or 15,y1=C or 15,x2=D or 50,y2=E or 45}if not(c==nil)and not(c=="")then g.stroke=c end;if not(v==nil)and not(v=="")then g["stroke-width"]=v end;if not(d==nil)and not(d=="")then g.fill=d end;return self.Element:create("line",g)end;function svg:addLine(B,C,D,E,c,v,d)self:add(self:Line(B,C,D,E,c,v,d))end;function svg:Polyline(F,c,v,d,u)local g={points=F or"10,10 50,50 50,25 75,25"}if not(c==nil)and not(c=="")then g.stroke=c end;if not(v==nil)and not(v=="")then g["stroke-width"]=v end;if not(d==nil)and not(d=="")then g.fill=d end;if not(u==nil)and not(u=="")then g.transform=u end;return self.Element:create("polyline",g)end;function svg:addPolyline(F,c,v,d,u)self:add(self:Polyline(F,c,v,d,u))end;function svg:Path(G,c,v,d,u)local g={d=G or"M50 0 L75 100 L25 100 Z"}if not(c==nil)and not(c=="")then g.stroke=c end;if not(v==nil)and not(v=="")then g["stroke-width"]=v end;if not(d==nil)and not(d=="")then g.fill=d end;if not(u==nil)and not(u=="")then g.transform=u end;return self.Element:create("path",g)end;function svg:addPath(G,c,v,d,u)self:add(self:Path(G,c,v,d,u))end