Hilbert curve: Difference between revisions
m
→JS Functional: Tidied
m (→JS Functional: Tidied) |
|||
Line 2,013:
// hilbertCurve :: Dict Char [(Int, Int)] ->
// Dict Char [Char] -> Int -> Int -> SVG string
const hilbertCurve = dictVector =>
dictRule =>
▲ hilbertPoints(dictVector)(w)(
hilbertTree(dictRule)(n)▼
)▼
);▼
▲ };
// hilbertTree :: Dict Char [Char] -> Int -> Tree Char
const hilbertTree = rule =>
const
const xs = tree.nest;
return Node(tree.root)(
? xs.map(go)
flip(Node)([])
)
▲ );
const seed = Node("a")([]);▼
)
.slice(-1)
};
▲ const seed = Node("a")([]);
▲ return Boolean(n) ? (
▲ .slice(-1)[0]
▲ ) : seed;
};▼
Line 2,061 ⟶ 2,060:
]);
return
? zipWith(
: 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 =>
1 !== op.length
? (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 ---
|