add pick_random

This commit is contained in:
mehbark 2023-09-02 21:08:44 -04:00
parent 87496620f2
commit a74799d393
3 changed files with 26 additions and 1 deletions

View file

@ -0,0 +1,19 @@
import { Main, pick_random, render_and_copy } from "./common.tsx";
// thanks, https://dwarffortresswiki.org/index.php/Grass
const grass_chars = ".,'`".split("");
const Blade = () => <div>{pick_random(grass_chars)}</div>;
const Field = ({ width }: { width: number }) => (
<div
style={{
width: "100%",
aspectRatio: "1",
display: "grid",
gridRow: `repeat(1fr, ${width})`,
gridColumn: `repeat(1fr, ${width})`,
}}
></div>
);
render_and_copy(<Field width={50} />);

View file

@ -187,3 +187,8 @@ export const static_url = (res: string) => `https://static.pyrope.net/${res}`;
export const randirect = (...urls: string[]) =>
`https://pyrope.net/randirect#${urls.join("::")}`;
// could do some [T, ...T[]] shenanigans for totality but meh
// kinda bad name
export const pick_random = <T,>(xs: T[]): T =>
xs[Math.floor(Math.random() * xs.length)];

View file

@ -8,7 +8,7 @@
<style>
body {
margin: 0 auto;
width: min(500px, 100vw);
width: min(500px, 96vw);
}
</style>
</head>
@ -36,3 +36,4 @@ winners:
</body>
</html>