Something went wrong. Try again.
Monorepo for Tangled forked from tangled.org/core
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262<script lang="ts"> import Guide from "#lib/components/landing/selfhost/electronics/Guide.svelte"; import Plate from "#lib/components/landing/selfhost/electronics/Plate.svelte"; import Solid from "#lib/components/landing/selfhost/electronics/Solid.svelte"; import Logo from "#lib/components/landing/selfhost/electronics/Logo.svelte"; import { Insert } from "#lib/components/landing/selfhost/electronics/insert.svelte.ts"; import { circle, inset, prism, rect, rounded, sketch, span, subdivide, type Pt } from "#lib/components/landing/selfhost/electronics/iso.ts"; import { Loop } from "#lib/components/landing/selfhost/electronics/loop.svelte.ts";
interface Props { class?: string; /** Holds the animation still, e.g. while the drawing is hidden. */ paused?: boolean; ontoggle?: (inserted: boolean) => void; }
let { class: className = "", paused = false, ontoggle }: Props = $props();
const VIEW = { cx: 322, cy: 350, scale: 1.75 }; const CASE = { x0: 0, y0: -14, x1: 160, y1: 150, back: 48, lip: 24, ledge: 76, r: 8 }; const SEAM_Z = 15; const VENTS = { count: 16, from: CASE.y0 + 10, pitch: 5, z0: 24, z1: 40 }; const KEY = { pitch: 10.3, size: 8.4, height: 2.6, r: 1.4 }; const KEY_ROWS = [ { v: 10, from: 17, n: 12 }, { v: 21, from: 20, n: 12 }, { v: 32, from: 23, n: 11 }, { v: 43, from: 28, n: 10 } ]; const SPACE_BAR = { u0: 44, u1: 116, v: 55 }; const WELL = { x0: 12, y0: 6, x1: 148, y1: 70, r: 4 }; const DRIVE = { y0: CASE.y0 + 2, y1: 70, z0: CASE.back, z1: CASE.back + 34, width: 72 }; const DRIVES = [6, 82]; const SLOT = { x0: 8, x1: 64, z0: DRIVE.z0 + 15, z1: DRIVE.z0 + 24 }; const MONITOR = { x0: 6, x1: 154, y0: CASE.y0, y1: 62, z0: DRIVE.z1, z1: DRIVE.z1 + 112, r: 8 }; const CHAMFER = { y: 22, drop: 22 }; const FRAME = { x0: 3, x1: 157, y1: DRIVE.y1, z1: MONITOR.z1 + 3, r: 9 }; const OPENING = { x0: 16, x1: 144, z0: MONITOR.z0 + 15, z1: FRAME.z1 - 13, r: 11 }; const TUBE = { x0: 20, x1: 141, z0: MONITOR.z0 + 18, z1: FRAME.z1 - 15, r: 12, inset: 5 }; const DISK = { x0: DRIVES[0]! + 12, size: 48, z: SLOT.z0 + 3, thick: 2, out: 16, bob: 5 }; const DISK_IN = DISK.size + 4; const LOGO_SIZE = 14; const BLINK_RATE = 9; const TIMING = { drop: 520, lift: 700, on: 700, off: 220 }; const SCREEN = { off: "color-mix(in srgb, var(--color-foreground-subtle) 30%, black)", on: "var(--color-drawing-accent)" };
const uid = $props.id(); const { at, coord, line, face, block, extrude, seam, mark } = sketch( VIEW.cx, VIEW.cy, VIEW.scale );
const onFront = ( x0: number, z0: number, x1: number, z1: number, r: number, y: number, steps?: number ) => face("front", rounded(span(x0, z0, x1, z1), r, steps), y); const raised = (outline: Pt[], z0: number, height: (y: number) => number) => prism(subdivide(outline, 3), 0, 1, (x, y, top) => coord(x, y, top ? height(y) : z0)); const fold = (y: number, at: number, bend: number, level: number, slope: number) => y <= at - bend ? level : y >= at + bend ? level + slope * (y - at) : level + (slope * (y - at + bend) ** 2) / (4 * bend);
const slope = (() => { const dy = CASE.y1 - CASE.ledge; const dz = CASE.lip - CASE.back; const l = Math.hypot(dy, dz); return { ty: dy / l, tz: dz / l, ny: -dz / l, nz: dy / l }; })(); const onSlope = (u: number, v: number, d: number) => coord(u, CASE.ledge + v * slope.ty + d * slope.ny, CASE.back + v * slope.tz + d * slope.nz);
const casePlan = rounded(CASE, CASE.r, 6); const shell = raised(casePlan, 0, (y) => fold(y, CASE.ledge, 6, CASE.back, (CASE.lip - CASE.back) / (CASE.y1 - CASE.ledge)) ); const caseSeam = seam(casePlan, SEAM_Z); const vents = Array.from({ length: VENTS.count }, (_, k) => VENTS.from + k * VENTS.pitch).map( (y) => line([CASE.x1, y, VENTS.z0], [CASE.x1, y, VENTS.z1]) );
const well = `M${rounded(WELL, WELL.r) .map(([u, v]) => onSlope(u, v, 0)) .join(" L")} Z`; const keys = [ ...KEY_ROWS.flatMap(({ v, from, n }) => Array.from({ length: n }, (_, k) => { const u = from + k * KEY.pitch; return rounded(span(u, v, u + KEY.size, v + KEY.size), KEY.r); }) ), rounded(span(SPACE_BAR.u0, SPACE_BAR.v, SPACE_BAR.u1, SPACE_BAR.v + KEY.size), KEY.r) ].map((outline) => prism(outline, 0, KEY.height, onSlope));
const drives = DRIVES.map((x0) => { const x1 = x0 + DRIVE.width; const { y1, z0, z1 } = DRIVE; return { box: block({ ...DRIVE, x0, x1 }, 3), panel: face("front", rounded(inset(span(x0, z0, x1, z1), 3), 2), y1), slot: onFront(x0 + SLOT.x0, SLOT.z0, x0 + SLOT.x1, SLOT.z1, 1.5, y1), led: onFront(x0 + 7, z0 + 6, x0 + 14, z0 + 9, 1, y1) }; });
const monitor = raised(rounded(MONITOR, MONITOR.r, 6), MONITOR.z0, (y) => fold(-y, -CHAMFER.y, 6, MONITOR.z1, -CHAMFER.drop / (CHAMFER.y - MONITOR.y0)) ); const ventPanel = (() => { const y = (MONITOR.y0 + MONITOR.y1) / 2; const z = (MONITOR.z0 + MONITOR.z1 - CHAMFER.drop / 2) / 2; return { y0: y - 21, y1: y + 21, z0: z - 17, z1: z + 17 }; })(); const panel = face( "side", rounded(span(ventPanel.y0, ventPanel.z0, ventPanel.y1, ventPanel.z1), 3), MONITOR.x1 ); const panelVents = Array.from( { length: Math.floor((ventPanel.y1 - ventPanel.y0 - 10) / 5) + 1 }, (_, k) => ventPanel.y0 + 5 + k * 5 ).map((y) => line([MONITOR.x1, y, ventPanel.z0 + 6], [MONITOR.x1, y, ventPanel.z1 - 6])); const frame = extrude( "front", rounded(span(FRAME.x0, MONITOR.z0, FRAME.x1, FRAME.z1), FRAME.r, 6), MONITOR.y1, FRAME.y1 ); const opening = onFront(OPENING.x0, OPENING.z0, OPENING.x1, OPENING.z1, OPENING.r, FRAME.y1, 6); const tube = onFront(TUBE.x0, TUBE.z0, TUBE.x1, TUBE.z1, TUBE.r, FRAME.y1 - TUBE.inset, 6);
const insert = new Insert(TIMING); let svg = $state<SVGSVGElement>(); const loop = new Loop(() => svg, { when: () => !paused });
const busy = $derived.by(() => { const k = Math.floor(loop.time * BLINK_RATE); return insert.lit && (Math.imul(k, 2654435761) >>> 0) % 5 < 3; }); const screen = $derived( `color-mix(in srgb, ${SCREEN.on} ${(insert.power.current * 100).toFixed(1)}%, ${SCREEN.off})` );
const disk = $derived.by(() => { const { x0, size, z, thick } = DISK; const back = DRIVE.y1 - DISK_IN + insert.hang(loop.time, DISK_IN + DISK.out, DISK.bob); const top = z + thick; const x1 = x0 + size; const onDisk = (outline: Pt[]) => face( "top", outline.map(([a, b]) => [x0 + a, back + b]), top ); const mid = z + thick / 2; return { body: block({ x0, y0: back, x1, y1: back + size, z0: z, z1: top }, 1.5), clip: face("top", rect(span(-400, DRIVE.y1, 600, DRIVE.y1 + 600)), mid), logo: mark("top", [x0 + size / 2, back + 39, top], LOGO_SIZE), guides: back > DRIVE.y1 + 4 ? [x0 + 5, x1 - 5].map((x) => [at(x, back, z + 1), at(x, DRIVE.y1, z + 1)]) : [], label: onDisk(rounded(span(6, 30, size - 6, 47), 1.5)), hub: onDisk(circle([size / 2, size / 2], 8.5)), holes: [ onDisk(circle([size / 2, size / 2], 5)), onDisk(circle([size / 2 + 11, size / 2 - 3], 1.4, 12)), onDisk(rounded(span(size / 2 - 3, 3, size / 2 + 3, 16), 3)), onDisk(rounded(span(size - 3, 30, size + 0.2, 36), 0.6)) ] }; });</script>
<Plate {insert} labels={{ insert: "Insert the Tangled floppy disk", eject: "Eject the Tangled floppy disk" }} bind:svg {ontoggle} class={className}> <defs> <clipPath id="{uid}-disk"><path d={disk.clip} /></clipPath> <clipPath id="{uid}-tube"><path d={opening} /></clipPath> </defs>
<g class="sh-line" stroke-width="1.25"> <Solid shape={shell} /> <path d={caseSeam} fill="none" stroke-width="1" /> {#each vents as d, i (i)} <path {d} fill="none" stroke-width="1" /> {/each}
{#each drives as drive, i (i)} <Solid shape={drive.box} /> <path d={drive.panel} class="sh-side" stroke-width="1" /> <path d={drive.slot} class="sh-hole" stroke-width="1" /> <path d={drive.led} class={i === 0 && busy ? "fill-drawing-accent" : "sh-hole"} stroke-width="0.75" /> {/each}
<Solid shape={monitor} /> <path d={panel} class="sh-side" stroke-width="1" /> {#each panelVents as d, i (i)} <path {d} fill="none" stroke-width="1" /> {/each} <Solid shape={frame} /> <path d={opening} class="sh-hole" stroke="none" /> <g clip-path="url(#{uid}-tube)"> <path d={tube} style:fill={screen} stroke-width="1" /> </g> <path d={opening} fill="none" />
<path d={well} class="sh-hole" stroke-width="1" /> <g stroke-width="0.75"> {#each keys as shape, i (i)} <Solid {shape} /> {/each} </g> </g>
{#each disk.guides as [from, to], i (i)} <Guide {from} {to} /> {/each}
<g clip-path="url(#{uid}-disk)" class="stroke-drawing-accent-edge" stroke-width="1.25"> <Solid shape={disk.body} class="fill-drawing-accent" side="sh-accent-side"> <path d={disk.label} class="fill-drawing-accent-recess" stroke="none" /> <path d={disk.hub} class="fill-drawing-accent-recess" stroke="none" /> {#each disk.holes as d, i (i)} <path {d} class="fill-drawing-accent-edge" stroke="none" /> {/each} </Solid> <Logo transform={disk.logo} /> </g></Plate>