Pythagoras tree: Difference between revisions

Content added Content deleted
(→‎{{trans|Rust}}: refactoring)
m (→‎{{trans|Rust}}: cosmetics comments)
Line 986: Line 986:
const svg = doc.replace('<svg ', `<svg viewBox="${[x, y, -x - x, -y]}" `);
const svg = doc.replace('<svg ', `<svg viewBox="${[x, y, -x - x, -y]}" `);


if (globalThis.global) { // if script is run from node.js - save svg to file
if (globalThis.global) { // if the script is run from node.js - save the svg to a file
require('node:fs').writeFileSync('Pythagor_tree.svg', svg);
require('node:fs').writeFileSync('Pythagor_tree.svg', svg);
} else { // if the script is run from the browser console or from the <script> tag of the html document
} else { // if is run from the browser console or from the <script> tag of an html document
// - display the svg in the browser window
// - display svg in the browser window
document.body.innerHTML = svg, '';
document.body.innerHTML = svg, '';
}</syntaxhighlight>
}</syntaxhighlight>