Jump to content

Pythagoras tree: Difference between revisions

(→‎{{header|JavaScript}}: added translation of Rust)
(→‎{{trans|Rust}}: refactoring)
Line 973:
<syntaxhighlight lang="javascript">let base = [[[-200, 0], [200, 0]]];
const doc = [...Array(12)].reduce((doc_a, _, lvl) => {
const rg = step => ('`0' + ${((80 + (lvl - 2) * step) % 256).toString(16))}`.slice(-2);
return doc_a + base0base.splice(0).reduce((ga, [a, b]) => {
const base0 = base;
base = [];
return doc_a + base0.reduce((ga, [a, b]) => {
const v = [b[0] - a[0], b[1] - a[1]];
const [c, d, w] = [a, b, v].map(p => [p[0] + v[1], p[1] - v[0]]);
Line 990 ⟶ 988:
if (globalThis.global) { // if script is run from node.js - save svg to file
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
// - display the svg in the browser window
document.body.innerHTML = svg, '';
}</syntaxhighlight>
106

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.