diff --git a/www/components/Icons.tsx b/www/components/Icons.tsx index f2fe615d..adb729ad 100644 --- a/www/components/Icons.tsx +++ b/www/components/Icons.tsx @@ -41,3 +41,20 @@ export function IconPlus() { ); } + +export function Leaf() { + return ( + + + + + + ); +} diff --git a/www/components/WaveTank.ts b/www/components/WaveTank.ts new file mode 100644 index 00000000..b8bdb97a --- /dev/null +++ b/www/components/WaveTank.ts @@ -0,0 +1,51 @@ +export interface Spring { + p: number; + v: number; +} + +export class WaveTank { + springs = [] as Spring[]; + waveLength = 100; + k = 0.02; + damping = 0.02; + spread = 0.02; + + constructor() { + for (let i = 0; i < this.waveLength; i++) { + this.springs[i] = { + p: 0, + v: 0, + }; + } + } + + update(springs: Spring[]) { + for (const i of springs) { + const a = -this.k * i.p - this.damping * i.v; + i.p += i.v; + i.v += a; + } + + const leftDeltas = []; + const rightDeltas = []; + + for (let t = 0; t < 8; t++) { + for (let i = 0; i < springs.length; i++) { + const prev = springs[(i - 1 + springs.length) % springs.length]; + const next = springs[(i + 1) % springs.length]; + + leftDeltas[i] = this.spread * (springs[i].p - prev.p); + rightDeltas[i] = this.spread * (springs[i].p - next.p); + } + + for (let i = 0; i < springs.length; i++) { + const prev = springs[(i - 1 + springs.length) % springs.length]; + const next = springs[(i + 1) % springs.length]; + prev.v += leftDeltas[i]; + next.v += rightDeltas[i]; + prev.p += leftDeltas[i]; + next.p += rightDeltas[i]; + } + } + } +} diff --git a/www/fresh.gen.ts b/www/fresh.gen.ts index 0876344f..87f6ddc7 100644 --- a/www/fresh.gen.ts +++ b/www/fresh.gen.ts @@ -7,6 +7,7 @@ import * as $1 from "./routes/docs/[...slug].tsx"; import * as $2 from "./routes/gfm.css.ts"; import * as $3 from "./routes/index.tsx"; import * as $$0 from "./islands/Counter.tsx"; +import * as $$1 from "./islands/LemonDrop.tsx"; const manifest = { routes: { @@ -17,6 +18,7 @@ const manifest = { }, islands: { "./islands/Counter.tsx": $$0, + "./islands/LemonDrop.tsx": $$1, }, baseUrl: import.meta.url, }; diff --git a/www/islands/LemonDrop.tsx b/www/islands/LemonDrop.tsx new file mode 100644 index 00000000..ac126837 --- /dev/null +++ b/www/islands/LemonDrop.tsx @@ -0,0 +1,138 @@ +/** @jsx h */ +import { + Fragment, + h, + tw, + useEffect, + useRef, + useState, +} from "../client_deps.ts"; +import { Spring, WaveTank } from "../components/WaveTank.ts"; + +function easeInCirc(x: number) { + return 1 - Math.sqrt(1 - Math.pow(x, 2)); +} + +const waveTank = new WaveTank(); + +function LemonDrop() { + const [counter, setCounter] = useState(0); + const [dropy, setDropy] = useState(60); + const [width, setWidth] = useState(window.innerWidth); + const widthRef = useRef(width); + const [springs, setSprings] = useState([]); + const requestIdRef = useRef(); + const grid = width / waveTank.waveLength; + const points = [ + [0, 100], + [0, 0], + ...springs.map((x, i) => [i * grid, x.p]), + [width, 0], + [width, 100], + ]; + const springsPath = `${points.map((x) => x.join(",")).join(" ")}`; + const juice = `M18 ${63 + counter} C15 ${63 + counter} 16 ${ + 63 + counter + } 12 61L9 56C2 33 62 -3 80 12C103 27 44 56 29 58C27 58 25 59 24 61C20 ${ + 63 + counter + } 21 ${63 + counter} 18 ${63 + counter}Z`; + + function updateJuice(timestamp: number) { + const amp = 40; + const x = timestamp / 2000; + const saw = x - Math.floor(x); + if (saw < 0.6) { + setCounter(easeInCirc(saw) * amp); + setDropy(-100); + } else { + setCounter(easeInCirc(1 - saw) * amp * 0.1); + setDropy(70 + Math.pow(saw - 0.6, 2) * 10000); + } + } + + function update(timestamp: number) { + updateJuice(timestamp); + waveTank.update(waveTank.springs); + setSprings([...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() { + setWidth(document.body.clientWidth); + } + + function drop() { + const dropPosition = Math.round( + ((widthRef.current / 2 - 30) / widthRef.current) * 100, + ); + waveTank.springs[dropPosition].p = -60; + } + + useEffect(() => { + widthRef.current = width; + }, [width]); + + useEffect(() => { + requestIdRef.current = requestAnimationFrame(update); + globalThis.addEventListener("resize", resize); + resize(); + + return () => { + globalThis.removeEventListener("resize", resize); + if (requestIdRef.current !== undefined) { + cancelAnimationFrame(requestIdRef.current); + } + }; + }, []); + + return ( + + + + + + + + + + + + + + + ); +} + +export default LemonDrop; diff --git a/www/routes/index.tsx b/www/routes/index.tsx index d8fe5a2e..52107afb 100644 --- a/www/routes/index.tsx +++ b/www/routes/index.tsx @@ -1,11 +1,12 @@ /** @jsx h */ /** @jsxFrag Fragment */ -import { Fragment, h, Head, tw } from "../client_deps.ts"; +import { ComponentChildren, Fragment, h, Head, tw } from "../client_deps.ts"; import Counter from "../islands/Counter.tsx"; -import NavigationBar from "../components/NavigationBar.tsx"; +import LemonDrop from "../islands/LemonDrop.tsx"; import Footer from "../components/Footer.tsx"; import WarningBanner from "../components/WarningBanner.tsx"; +import { Leaf } from "../components/Icons.tsx"; export default function MainPage() { return ( @@ -18,7 +19,7 @@ export default function MainPage() { /> - + {/* */} @@ -28,53 +29,85 @@ export default function MainPage() { } function Hero() { - const container = tw`w-full h-64 flex justify-center items-center flex-col`; - const title = tw - `text(4xl sm:5xl lg:6xl gray-900 center) sm:tracking-tight font-extrabold`; - const subtitle = tw`mt-4 text(2xl gray-600 center)`; + const container = tw + `w-full flex justify-center items-center flex-col bg(green-200)`; + const nav = tw`flex justify-end items-center bg(green-200)`; + const a = tw + `border(1 black) inline-flex items-center h-10 px-4 m-4 text-black bg-transparent rounded hover:bg-white`; return ( -
-

- fresh -

-

- The next-gen web framework. -

-
+ + +
+ +
+
+ ); +} +export interface ListItemProps { + children: ComponentChildren; +} + +function ListItem(props: ListItemProps) { + return ( +
+ +
+ {props.children} +
+
); } function Intro() { + const title = tw + `text(4xl sm:4xl lg:4xl gray-900 center) sm:tracking-tight font-extrabold`; + return (
+ deno is drinking fresh lemon squash + +

+ The next-gen web framework. +

+

Fresh is a next generation web framework, built for speed, reliability, and simplicity. Some stand out features:

-
    -
  • + +
    + Just-in-time rendering on the edge. -
  • -
  • + + Island based client hydration for maximum interactivity. -
  • -
  • + + Zero runtime overhead: no JS is shipped to the client by default. -
  • -
  • + + No build step. -
  • -
  • + + No configuration necessary. -
  • -
  • + + TypeScript support out of the box. -
  • -
+ + +

Fresh embraces the tried and true design of server side rendering and progressive enhancement on the client side. diff --git a/www/static/illust.jpeg b/www/static/illust.jpeg new file mode 100644 index 00000000..88e06421 Binary files /dev/null and b/www/static/illust.jpeg differ