Hilbert curve: Difference between revisions

m
Line 2,013:
 
// hilbertCurve :: Dict Char [(Int, Int)] ->
// Dict Char [Char] -> Int -> Int -> SVG string
const hilbertCurve = dictVector =>
dictRule => nwidth => {compose(
const w = 1024;svgFromPoints(width),
hilbertPoints(dictVector)(wwidth)(,
 
return svgFromPointshilbertTree(wdictRule)(
});
hilbertPoints(dictVector)(w)(
hilbertTree(dictRule)(n)
)
);
};
 
 
// hilbertTree :: Dict Char [Char] -> Int -> Tree Char
const hilbertTree = rule => n => {
const go = treen => {
const xsgo = tree.nest; => {
const xs = tree.nest;
 
return Node(tree.root)(
Boolean( 0 < xs.length) ? (
? xs.map(go)
) : rule[tree.root].map(
flip(Node)([])
)
);
)};
const seed = Node("a")([]);
 
return Boolean(n)0 ?< (n
.slice ? take(-1n)[0](
hilbertTreeiterate(dictRulego)(nseed)
)
.slice(-1);[0]
) : seed;
};
const seed = Node("a")([]);
 
return Boolean(n) ? (
take(n)(iterate(go)(seed))
.slice(-1)[0]
) : seed;
};
 
 
Line 2,061 ⟶ 2,060:
]);
 
return Boolean(0 < t.nest.length) ? (
? zipWith(go(r))(centres)(t.nest)
.flat go(r)
) : )(centres;)(t.nest).flat()
: centres;
};
const d = Math.floor(w / 2);
Line 2,115:
c: ["b", "c", "c", "d"],
d: ["a", "d", "d", "c"]
})(1024)(6);
 
 
Line 2,130:
nest: xs || []
});
 
 
// compose (<<<) :: (b -> c) -> (a -> b) -> a -> c
const compose = (...fs) =>
// A function defined by the right-to-left
// composition of all the functions in fs.
fs.reduce(
(f, g) => x => f(g(x)),
x => x
} );
 
 
// flip :: (a -> b -> c) -> b -> a -> c
const flip = op =>
// The binary function op with
// its arguments reversed.
1 !== op.length ? (
? (a, b) => op(b, a)
) : (a => b => op(b)(a));
 
 
Line 2,163 ⟶ 2,173:
"GeneratorFunction" !== xs.constructor
.constructor.name ? (
xs.length
) : Infinity;
 
 
Line 2,174 ⟶ 2,184:
xs => "GeneratorFunction" !== xs
.constructor.constructor.name ? (
xs.slice(0, n)
) : Array.from({
length: n
}, () => {
const x = xs.next();
 
return x.done ? [] : [x.value];
}).flat();
 
 
Line 2,196 ⟶ 2,206:
}, (_, i) => f(as[i], bs[i]));
};
 
 
// MAIN ---
9,655

edits