From 7bf25db6a3389527cd349a281d27b1b0b438d0c3 Mon Sep 17 00:00:00 2001 From: mehbark Date: Wed, 6 Sep 2023 21:01:47 -0400 Subject: [PATCH] sunshine: feeling a bit stuck --- html/common.tsx | 38 +++++++++++++++ html/sunshine-curved-text.tsx | 92 ++++++++++++++++++++++++++--------- 2 files changed, 106 insertions(+), 24 deletions(-) diff --git a/html/common.tsx b/html/common.tsx index ee95c42..b761995 100644 --- a/html/common.tsx +++ b/html/common.tsx @@ -197,10 +197,13 @@ export const jitter = (n: number) => n * (Math.random() - 0.5); export const svg_url = (svg: string) => `data:image/svg+xml,${encodeURI(svg)}`; +// something higher-level might be worthwhile... +// could namespace; e.g. css.font.sans_serif export const css = { url(href: string) { return `url('${href}')`; }, + px(n: number) { return `${n}px`; }, @@ -210,8 +213,43 @@ export const css = { rem(n: number) { return `${n}rem`; }, + + deg(n: number) { + return `${n}deg`; + }, + rad(n: number) { + return `${n}rad`; + }, + turn(n: number) { + return `${n}turn`; + }, + // now i feel like this could be generalizable + // but js metaprogramming SUCKS + transform(...ts: string[]) { + return ts.join(" "); + }, + rotate(by: string) { + return `rotate(${by})`; + }, + translateX(by: string) { + return `translateX(${by})`; + }, + translateY(by: string) { + return `translateY(${by})`; + }, + translate(x: string, y: string) { + return `translate(${x}, ${y})`; + }, + + fontstack(...fonts: string[]) { + return fonts.join(", "); + }, + // # ruby i wont you .. inline_block: "inline-block", block: "block", grid: "grid", flex: "flex", + fit_content: "fit-content", + min_content: "min-content", + max_content: "max-content", } as const; diff --git a/html/sunshine-curved-text.tsx b/html/sunshine-curved-text.tsx index b335d70..ab5deec 100644 --- a/html/sunshine-curved-text.tsx +++ b/html/sunshine-curved-text.tsx @@ -1,29 +1,73 @@ import { css, render_and_copy, svg_url } from "./common.tsx"; -const svg = ` - - - - - - - - -`.trim(); +const displace = + (width: number, amplitude = 1) => + (t: number) => + amplitude * Math.sin((Math.PI / width) * t); + +const rotation = css.rotate(css.deg(-20)); + +const Row = ({ + children, + max_width = 10, +}: { + children: string; + max_width?: number; +}) => { + const d = displace(max_width); + const out = children.split("").map((c, i) => ( +
+ {c} +
+ )); + + return ( +
+ {...out} +
+ ); +}; + +const TextBox = ({ lines }: { lines: string[] }) => { + const max_width = Math.max(...lines.map(l => l.length)); + return ( +
+ {...lines.map(line => {line})} +
+ ); +}; render_and_copy( -
- yo what's up i am a chuckya -
+ );