[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.

base project

Thomas DAGES (Dec 6, 2018, 2:47 PM +0100) bc5b7c1e 460dd52b

+81
+81
svg.lua
··· 1 + -- INIT SVG Object 2 + svg = {} 3 + svg.__index = svg; 4 + 5 + -- function to create a SVG drawing 6 + -- width: number => width of the drawing 7 + -- height: number => height of the drawing 8 + -- stroke: string => lines color 9 + -- fill: string => fill color 10 + function svg:create(width, heigth, stroke, fill) 11 + local s = {} 12 + setmetatable(s,svg) 13 + s.width = width or 100 14 + s.height = height or 100 15 + s.stroke = stroke or "#000000" 16 + s.fill = fill or "transparent" 17 + s.elements = {} 18 + 19 + 20 + -- INIT svg.Element Object 21 + s.Element = {} 22 + s.Element.__index = svg.Element 23 + 24 + -- function to create svg.Element 25 + -- name: string => name of the element (standard svg element name) 26 + -- options: table => a table containing all the parameters of the element 27 + function s.Element:create(name, options) 28 + local e = {} 29 + setmetatable(e,s.Element) 30 + e.name = name 31 + e.strElement = "<" .. name .. " " 32 + for key, value in pairs(options) do 33 + e[key] = value 34 + e.strElement = e.strElement .. key .. "=\"" .. value .. "\" " 35 + end 36 + e.strElement = e.strElement .. "/>" 37 + return e; 38 + end 39 + 40 + return s 41 + end 42 + 43 + -- function to add an element to the svg drawing 44 + -- element : svg.Element => the element to add to the drawing 45 + function svg:add(element) 46 + table.insert(self.elements, element) 47 + end 48 + 49 + -- function to get the string formatted for the full svg drawing 50 + function svg:draw() 51 + 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\">" 52 + for k,v in pairs(self.elements) do 53 + svgStr = svgStr .. v.strElement 54 + end 55 + svgStr = svgStr .. "</svg>" 56 + return svgStr 57 + end 58 + 59 + -- INIT Rect element Class 60 + -- x: number => Position du rectangle sur l'axe horizontal par rapport au coin supérieur gauche 61 + -- y: number => Position du rectangle sur l'axe vertical par rapport au coin supérieur gauche 62 + -- width: number => Largeur du rectangle 63 + -- height: number => Hauteur du rectangle. 64 + -- stroke: string => lines color 65 + -- strokeWidth: string => lines width 66 + -- fill: string => fill color 67 + -- rx: number => Rayon x des coins du rectangle 68 + -- ry: number => Rayon y des coins du rectangle 69 + function svg:Rect(x, y, width, height, stroke, strokeWidth, fill, rx, ry) 70 + return self.Element:create("rect", { 71 + x = x or 10, 72 + y = y or 10, 73 + width = width or 10, 74 + height = height or 10, 75 + stroke = stroke or svg.stroke, 76 + fill = fill or svg.fill, 77 + ["stroke-width"] = strokeWidth or 1, 78 + rx = rx or 0, 79 + ry = ry or 0 80 + }) 81 + end