···11+-- INIT SVG Object
22+svg = {}
33+svg.__index = svg;
44+55+-- function to create a SVG drawing
66+-- width: number => width of the drawing
77+-- height: number => height of the drawing
88+-- stroke: string => lines color
99+-- fill: string => fill color
1010+function svg:create(width, heigth, stroke, fill)
1111+ local s = {}
1212+ setmetatable(s,svg)
1313+ s.width = width or 100
1414+ s.height = height or 100
1515+ s.stroke = stroke or "#000000"
1616+ s.fill = fill or "transparent"
1717+ s.elements = {}
1818+1919+2020+ -- INIT svg.Element Object
2121+ s.Element = {}
2222+ s.Element.__index = svg.Element
2323+2424+ -- function to create svg.Element
2525+ -- name: string => name of the element (standard svg element name)
2626+ -- options: table => a table containing all the parameters of the element
2727+ function s.Element:create(name, options)
2828+ local e = {}
2929+ setmetatable(e,s.Element)
3030+ e.name = name
3131+ e.strElement = "<" .. name .. " "
3232+ for key, value in pairs(options) do
3333+ e[key] = value
3434+ e.strElement = e.strElement .. key .. "=\"" .. value .. "\" "
3535+ end
3636+ e.strElement = e.strElement .. "/>"
3737+ return e;
3838+ end
3939+4040+ return s
4141+end
4242+4343+-- function to add an element to the svg drawing
4444+-- element : svg.Element => the element to add to the drawing
4545+function svg:add(element)
4646+ table.insert(self.elements, element)
4747+end
4848+4949+-- function to get the string formatted for the full svg drawing
5050+function svg:draw()
5151+ local svgStr = "<svg width=\"" .. self.width .. "\" height=\"" .. self.height .. "\" fill=\"" .. self.fill .. "\" stroke=\"" .. self.stroke .. "\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">"
5252+ for k,v in pairs(self.elements) do
5353+ svgStr = svgStr .. v.strElement
5454+ end
5555+ svgStr = svgStr .. "</svg>"
5656+ return svgStr
5757+end
5858+5959+-- INIT Rect element Class
6060+-- x: number => Position du rectangle sur l'axe horizontal par rapport au coin supérieur gauche
6161+-- y: number => Position du rectangle sur l'axe vertical par rapport au coin supérieur gauche
6262+-- width: number => Largeur du rectangle
6363+-- height: number => Hauteur du rectangle.
6464+-- stroke: string => lines color
6565+-- strokeWidth: string => lines width
6666+-- fill: string => fill color
6767+-- rx: number => Rayon x des coins du rectangle
6868+-- ry: number => Rayon y des coins du rectangle
6969+function svg:Rect(x, y, width, height, stroke, strokeWidth, fill, rx, ry)
7070+ return self.Element:create("rect", {
7171+ x = x or 10,
7272+ y = y or 10,
7373+ width = width or 10,
7474+ height = height or 10,
7575+ stroke = stroke or svg.stroke,
7676+ fill = fill or svg.fill,
7777+ ["stroke-width"] = strokeWidth or 1,
7878+ rx = rx or 0,
7979+ ry = ry or 0
8080+ })
8181+end