vtm/quelldatein/manifestation/svg/svg.ts
Christian Fraß dac259a252 speicherung
2018-03-27 17:24:31 +02:00

107 lines
2.9 KiB
TypeScript

/*
* Verrückte Turing-Maschinen — A turing complete game
* Copyright (C) 2016 Christian Fraß <vidofnir@folksprak.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
module mod_vtm
{
export module mod_manifestation
{
export module mod_svg
{
/**
* @author kcf <vidofnir@folksprak.org>
*/
export const float_praezission : int = 4;
/**
* @author kcf <vidofnir@folksprak.org>
*/
export const form_pfeil : string = "M +4 0 L 0 +1 L 0 -1 Z";
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function pfad
(
vertices : Array<mod_vtm.mod_helfer.mod_vektor.typ_vektor>,
schliessen : boolean = true,
attribute : {[schlussel : string] : string} = {},
)
: mod_vtm.mod_helfer.mod_xml.typ_knoten
{
let d : string = "";
vertices.forEach
(
(vertex, index) =>
{
let c : string = ((index <= 0) ? "M" : "L");
let x : string = vertex.x.toFixed(float_praezission);
let y : string = vertex.y.toFixed(float_praezission);
d += [c, x, y].join(" ");
}
)
;
if (schliessen)
d += "Z";
attribute["d"] = d;
return (mod_vtm.mod_helfer.mod_xml.mod_normal.erstellen_erweitert("path", attribute));
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function wurzel
(
von_x : float,
von_y : float,
bis_x : float,
bis_y : float,
hoehe : int = 500,
breite : int = 500,
kinder : Array<mod_vtm.mod_helfer.mod_xml.typ_knoten> = []
)
: mod_vtm.mod_helfer.mod_xml.typ_knoten
{
return (
mod_vtm.mod_helfer.mod_xml.mod_normal.erstellen_erweitert
(
"svg",
{
"xmlns": "http://www.w3.org/2000/svg",
"xmlns:xlink": "http://www.w3.org/1999/xlink",
"width": breite.toFixed(0),
"height": hoehe.toFixed(0),
"viewBox": [von_x.toFixed(4), von_y.toFixed(4), (bis_x-von_x).toFixed(4), (bis_y-von_y).toFixed(4)].join(" "),
},
kinder,
)
);
}
}
}
}