vtm/quelldatein/manifestation/svg/_svg.ts

164 lines
3.7 KiB
TypeScript
Raw Normal View History

2017-11-09 14:06:35 +01:00
/*
* 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/>.
*/
2017-11-08 15:05:06 +01:00
2018-03-26 14:22:20 +02:00
module mod_vtm
2017-11-08 15:05:06 +01:00
{
2018-03-26 14:22:20 +02:00
export module mod_manifestation
2017-11-08 18:41:56 +01:00
{
2018-03-26 14:22:20 +02:00
export module mod_svg
{
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-28 13:59:29 +02:00
export const float_precision : int = 4;
2018-03-26 14:22:20 +02:00
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-28 13:59:29 +02:00
export const shape_arrow : string = "M +4 0 L 0 +1 L 0 -1 Z";
2018-03-26 14:22:20 +02:00
2018-03-28 12:09:27 +02:00
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function rotation
(
staerke : float
)
: string
{
return (
"rotate"
+ "("
2018-03-28 13:59:29 +02:00
+ (staerke * 360).toFixed(float_precision)
2018-03-28 12:09:27 +02:00
+ ")"
);
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function translation
(
x : float,
y : float
)
: string
{
return (
"translate"
+ "("
2018-03-28 13:59:29 +02:00
+ x.toFixed(float_precision)
2018-03-28 12:09:27 +02:00
+ ", "
2018-03-28 13:59:29 +02:00
+ y.toFixed(float_precision)
2018-03-28 12:09:27 +02:00
+ ")"
);
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function skalierung
(
staerke : float
)
: string
{
return (
"scale"
+ "("
2018-03-28 13:59:29 +02:00
+ staerke.toFixed(float_precision)
2018-03-28 12:09:27 +02:00
+ ")"
);
}
2018-03-26 14:22:20 +02:00
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-28 13:59:29 +02:00
export function path
2018-03-26 14:22:20 +02:00
(
2018-03-28 13:59:29 +02:00
vertices : Array<lib_vector.type_vector>,
close : boolean = true,
attributes : {[schlussel : string] : string} = {},
2018-03-26 14:22:20 +02:00
)
2018-03-28 13:59:29 +02:00
: lib_xml.type_node
2017-11-08 18:41:56 +01:00
{
2018-03-26 14:22:20 +02:00
let d : string = "";
vertices.forEach
(
(vertex, index) =>
{
let c : string = ((index <= 0) ? "M" : "L");
2018-03-28 13:59:29 +02:00
let x : string = vertex.x.toFixed(float_precision);
let y : string = vertex.y.toFixed(float_precision);
2018-03-26 14:22:20 +02:00
d += [c, x, y].join(" ");
}
)
;
2018-03-28 13:59:29 +02:00
if (close)
2018-03-26 14:22:20 +02:00
d += "Z";
2018-03-28 13:59:29 +02:00
attributes["d"] = d;
return (lib_xml.create_normal("path", attributes));
2017-11-08 18:41:56 +01:00
}
2018-03-26 14:22:20 +02:00
/**
* @author kcf <vidofnir@folksprak.org>
*/
2018-03-28 13:59:29 +02:00
export function root
2018-03-26 14:22:20 +02:00
(
von_x : float,
von_y : float,
bis_x : float,
bis_y : float,
hoehe : int = 500,
breite : int = 500,
2018-03-28 13:59:29 +02:00
children : Array<lib_xml.type_node> = []
2018-03-26 14:22:20 +02:00
)
2018-03-28 13:59:29 +02:00
: lib_xml.type_node
2017-11-08 15:05:06 +01:00
{
2018-03-26 14:22:20 +02:00
return (
2018-03-28 13:59:29 +02:00
lib_xml.create_normal
2018-03-26 14:22:20 +02:00
(
"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(" "),
},
2018-03-28 13:59:29 +02:00
children,
2018-03-26 14:22:20 +02:00
)
);
}
}
2017-11-08 15:05:06 +01:00
}
}