Module:User:Anomie/svg test
Appearance
local p = {}
local pi = math.pi
local sin = math.sin
local cos = math.cos
function p.star()
local paths = {}
local colors = { 'db8', 'db8', 'a86', 'cb7', 'bab', 'a86', 'bab', 'bab', 'cb7', 'cb7' }
for i = 0, 9, 1 do
local r1 = ( i % 2 ) ~= 0 and 5 or 10
local r2 = ( i % 2 ) ~= 0 and 10 or 5
local x1 = r1 * -sin( 2 * pi * i / 10 )
local y1 = r1 * -cos( 2 * pi * i / 10 )
local x2 = r2 * -sin( 2 * pi * ( i + 1 ) / 10 )
local y2 = r2 * -cos( 2 * pi * ( i + 1 ) / 10 )
table.insert( paths, string.format( '<path fill="#%s" d="M 0,0 %+0.3f,%+0.3f %+0.3f,%+0.3f"/>', colors[i+1], x1, y1, x2, y2 ) )
end
local colors = { 'a86', 'ca8', 'bab', 'ca6', 'ca8', 'cb7', 'cb7', 'a86', 'ca6', 'bab' }
for i = 0, 9, 1 do
local x1 = 5 * -sin( 2 * pi * i / 10 )
local y1 = 5 * -cos( 2 * pi * i / 10 )
local x2 = 5 * -sin( 2 * pi * ( i + 1 ) / 10 )
local y2 = 5 * -cos( 2 * pi * ( i + 1 ) / 10 )
table.insert( paths, string.format( '<path fill="#%s" d="M 0,0 %+0.3f,%+0.3f %+0.3f,%+0.3f"/>', colors[i+1], x1, y1, x2, y2 ) )
end
local lines = {}
for i = 0, 8, 2 do
local x = 10 * -sin( 2 * pi * i / 10 )
local y = 10 * -cos( 2 * pi * i / 10 )
table.insert( lines, string.format( 'M 0,0 %+0.3f,%+0.3f', x, y ) )
end
table.insert( paths, string.format( '<path d="%s" fill="none" stroke="#000" stroke-width=".2"/>', table.concat( lines, ' ' ) ) )
local points = {}
for i = 0, 9, 1 do
local r = ( i % 2 ) ~= 0 and 5 or 10
local x = r * -sin( 2 * pi * i / 10 )
local y = r * -cos( 2 * pi * i / 10 )
table.insert( points, string.format( '%+0.3f,%+0.3f', x, y ) )
end
table.insert( paths, string.format( '<path d="M %s Z" fill="none" stroke="#000" stroke-width=".2"/>', table.concat( points, ' ' ) ) )
return mw.svg.new()
:setAttribute( 'width', '20' )
:setAttribute( 'height', '20' )
:setAttribute( 'viewBox', '-10 -10.976 20 20' )
:setContent( table.concat( paths, "" ) )
:setImgAttribute( 'width', '20' )
:setImgAttribute( 'height', '20' )
:setImgAttribute( 'alt', 'â' )
:toImage()
end
return p