cohost/html/rain.tsx

68 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-11-15 02:27:53 -05:00
import { render_and_copy } from "./common.tsx";
2023-11-15 03:00:23 -05:00
const Drop = ({ color = "red", i }: { color?: string; i: number }) => (
2023-11-15 02:27:53 -05:00
<div
style={{
backgroundColor: color,
2023-11-15 03:00:23 -05:00
animation: `${(Math.random() * 2 + 5).toFixed(
2
)}s cubic-bezier(.55,.09,.68,.53) ${(-Math.random() * 10).toFixed(
2
)}s spin infinite reverse`,
2023-11-15 02:27:53 -05:00
gridRow: "1",
gridColumn: `${i}`,
2023-11-15 03:00:23 -05:00
width: "1px",
height: "1px",
2023-11-15 02:27:53 -05:00
marginTop: "-1rem",
transform: "translateY(20rem)",
}}
class="drop"
></div>
);
const Water = ({
color = "red",
duration_s,
}: {
color?: string;
duration_s: number;
}) => (
<div
style={{
backgroundColor: color,
gridRow: "1 / 2",
gridColumn: "1 / 100000",
transform: "translateY(100%)",
2023-11-15 03:00:23 -05:00
animation: `${duration_s}s linear 0s 1 spin forwards`,
2023-11-15 02:27:53 -05:00
}}
></div>
);
const Rain = ({
duration_s,
color = "red",
drops = 100,
}: {
duration_s: number;
color?: string;
drops?: number;
}) => (
<div
style={{
width: "25%",
aspectRatio: "1",
margin: "auto",
outline: "1px solid red",
display: "grid",
overflow: "clip",
}}
>
{...Array.from({ length: drops }, (_, i) => (
2023-11-15 03:00:23 -05:00
<Drop i={i} color={color} />
2023-11-15 02:27:53 -05:00
))}
<Water color={color} duration_s={duration_s} />
</div>
);
2023-11-15 03:00:23 -05:00
render_and_copy(<Rain duration_s={600} drops={150} />);