File talk:Peroxisome.svg

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Below is the Lua program I wrote to create the SVG. It prints the SVG to standard output. This program is in the public domain.

local COLOR = {
    core = '#7d7eb8',
    label = '#000',
    lipid_band = '#50b865',
    lipid_head = '#fefa61',
    lipid_head_edge = '#c7cc00',
    lipid_tail = '#008d2a',
    matrix = '#5fcadf',
}
local FONT = "font-family:'Bitstream Vera Sans;font-size:26px"

local ORAD, IRAD = 300, 275     -- outer and inner
local NUM_LIPIDS = 180
local MARGIN = 10
local CX, CY = MARGIN + ORAD, MARGIN + ORAD
local IMG_WD, IMG_HT = 2 * CX, 2 * CY

local out = io.write
local pi = math.pi
function circle (cx, cy, r, style)
    out(' <circle cx="', cx, '" cy="', cy, '" r="', r, '"')
    if style then out(' style="', style, '"') end
    out('/>\n')
end

function deg2rad (a)
    return a / 180 * pi
end

out('<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n',
    '<svg svg="http://www.w3.org/2000/svg" version="1.0"',
    ' width="', IMG_WD, '" height="', IMG_HT, '">\n')

circle(CX, CY, ORAD, 'fill:' .. COLOR.lipid_band)
circle(CX, CY, IRAD, 'fill:' .. COLOR.matrix)

local LIPID_ANG = (2 * pi) / NUM_LIPIDS
for n = 1, NUM_LIPIDS do
    for _, lipid in pairs{
        { offset = 0,   head_r = IRAD, tail_r = ORAD },
        { offset = 0.5, head_r = ORAD, tail_r = IRAD },
    } do
        local a = (n + lipid.offset) * LIPID_ANG
        local hx = CX + lipid.head_r * math.cos(a)
        local hy = CY + lipid.head_r * math.sin(a)
        local tx = CX + lipid.tail_r * math.cos(a)
        local ty = CY + lipid.tail_r * math.sin(a)
        local head_size = 2 * pi * lipid.head_r / NUM_LIPIDS
        out(' <path style="stroke-width:1;stroke:', COLOR.lipid_tail ..
            '" d="M', hx, ',', hy, ' L', tx, ',', ty, '"/>\n')
        circle(hx, hy, head_size / 2,
               'stroke:' .. COLOR.lipid_head_edge ..
               ';fill:' .. COLOR.lipid_head ..
               ';stroke-width:' .. (head_size / 10))
    end
end

-- Crystalized enzyme chunk in middle.
out(' <path transform="translate(', CX, ',', CY, ')"',
    ' style="fill:', COLOR.core, '"',
    ' d="M -134.52155,-75.750002 L -175.00862,-3.9181121 L -130.60345,88.810338 L -48.323279,94.034478 L 54.853451,92.728448 L 150.19397,113.625 L 185.4569,56.159478 L 193.2931,-27.426732 L 150.19397,-75.750012 L 78.362071,-88.810342 L -19.590509,-86.198282 L -134.52155,-75.750002 z"/>\n')

-- Labels
out(' <g style="', FONT, ';text-align:center;text-anchor:middle"',
    ' transform="translate(', CX, ',', CY, ')">\n',
    '  <text x="0" y="0"><tspan x="0" y="-16">Crystalloid core</tspan>',
    '<tspan x="0" y="17">(not always present)</tspan></text>\n',
    '  <text x="0" y="-150">Lipid bilayer membrane</text>\n',
    '  <path style="stroke-width:2;stroke:#000" d="M0,-180 L 90,-272"/>\n',
    ' </g>\n')
circle(CX + 90, CY - 272, 4, 'fill:#000')

out('</svg>\n')