-
+
+
{props.code}
-
+
-
- This area is interactive
+
+
+ Interactive island
-
+
The server supplied the initial value of 3.
count.value -= 1}
- disabled={!IS_BROWSER || count.value <= 0}
>
@@ -39,7 +34,6 @@ export default function Counter(props: CounterProps) {
count.value += 1}
- disabled={!IS_BROWSER}
>
@@ -47,3 +41,15 @@ export default function Counter(props: CounterProps) {
);
}
+
+function RoundedButton(props: JSX.HTMLAttributes
) {
+ return (
+
+ );
+}
diff --git a/www/islands/LemonBottom.tsx b/www/islands/LemonBottom.tsx
new file mode 100644
index 00000000..7474b1ae
--- /dev/null
+++ b/www/islands/LemonBottom.tsx
@@ -0,0 +1,118 @@
+import { useEffect, useRef } from "preact/hooks";
+import { useSignal } from "@preact/signals";
+import { WaveTank } from "../components/WaveTank.ts";
+
+function easeInCirc(x: number) {
+ return 1 - Math.sqrt(1 - Math.pow(x, 2));
+}
+
+const waveTank = new WaveTank();
+
+function LemonBottom() {
+ const SVG_WIDTH = 100;
+ const counter = useSignal(0);
+ const dropY = useSignal(60);
+ const width = useSignal(SVG_WIDTH);
+ const widthRef = useRef(width.value);
+ const springs = useSignal(waveTank.springs);
+ const requestIdRef = useRef();
+ const grid = SVG_WIDTH / waveTank.waveLength;
+ let lemonTop: SVGElement | null;
+ let lemonTopLeft: number;
+ const points = [
+ [0, 100],
+ [0, 0],
+ ...springs.value.map((x, i) => [i * grid, x.p]),
+ [width.value, 0],
+ [width.value, 100],
+ ];
+ const springsPath = `${points.map((x) => x.join(",")).join(" ")}`;
+
+ function updateJuice(timestamp: number) {
+ const amp = 40;
+ const x = timestamp / 2000;
+ const saw = x - Math.floor(x);
+ if (saw < 0.6) {
+ counter.value = easeInCirc(saw) * amp;
+ dropY.value = -100;
+ } else {
+ counter.value = easeInCirc(1 - saw) * amp * 0.1;
+ dropY.value = 70 + Math.pow(saw - 0.6, 2) * 10000;
+ }
+ }
+
+ function update(timestamp: number) {
+ updateJuice(timestamp);
+ waveTank.update(waveTank.springs);
+ springs.value = [...waveTank.springs];
+
+ const offset = 500;
+ const saw = (timestamp + offset) / 2000 -
+ Math.floor((timestamp + offset) / 2000);
+ if (saw < 0.01) {
+ drop();
+ }
+ requestIdRef.current = globalThis.requestAnimationFrame(update);
+ }
+
+ function resize() {
+ width.value = document.body.clientWidth;
+ lemonTop = document.querySelector("#lemon-top");
+ lemonTopLeft = lemonTop ? lemonTop.getBoundingClientRect().left + 25 : 50;
+ }
+
+ function drop() {
+ let dropPosition = 50;
+ if (widthRef.current >= 768) {
+ dropPosition = Math.round(100 / widthRef.current * lemonTopLeft);
+ } else {
+ dropPosition = Math.round(
+ ((widthRef.current / 2 - 30) / widthRef.current) * 100,
+ );
+ }
+ waveTank.springs[dropPosition].p = -40;
+ }
+
+ useEffect(() => {
+ widthRef.current = width.value;
+ }, [width.value]);
+
+ useEffect(() => {
+ const mediaQuery = globalThis.matchMedia(
+ "(prefers-reduced-motion: reduce)",
+ );
+ if (mediaQuery.matches) {
+ return;
+ }
+
+ requestIdRef.current = requestAnimationFrame(update);
+ globalThis.addEventListener("resize", resize);
+ resize();
+
+ return () => {
+ globalThis.removeEventListener("resize", resize);
+ if (requestIdRef.current !== undefined) {
+ cancelAnimationFrame(requestIdRef.current);
+ }
+ };
+ }, []);
+
+ return (
+
+ );
+}
+
+export default LemonBottom;
diff --git a/www/islands/LemonDrop.tsx b/www/islands/LemonDrop.tsx
index e54ecfaa..c2d3f9a4 100644
--- a/www/islands/LemonDrop.tsx
+++ b/www/islands/LemonDrop.tsx
@@ -11,7 +11,7 @@ const waveTank = new WaveTank();
function LemonDrop() {
const SVG_WIDTH = 100;
const counter = useSignal(0);
- const dropy = useSignal(60);
+ const dropY = useSignal(60);
const width = useSignal(SVG_WIDTH);
const widthRef = useRef(width.value);
const springs = useSignal(waveTank.springs);
@@ -37,10 +37,10 @@ function LemonDrop() {
const saw = x - Math.floor(x);
if (saw < 0.6) {
counter.value = easeInCirc(saw) * amp;
- dropy.value = -100;
+ dropY.value = -100;
} else {
counter.value = easeInCirc(1 - saw) * amp * 0.1;
- dropy.value = 70 + Math.pow(saw - 0.6, 2) * 10000;
+ dropY.value = 70 + Math.pow(saw - 0.6, 2) * 10000;
}
}
@@ -66,7 +66,7 @@ function LemonDrop() {
const dropPosition = Math.round(
((widthRef.current / 2 - 30) / widthRef.current) * 100,
);
- waveTank.springs[dropPosition].p = -60;
+ waveTank.springs[dropPosition].p = -40;
}
useEffect(() => {
@@ -96,16 +96,16 @@ function LemonDrop() {
return (
<>