From 2fbccaac7c254ab5db68db3ca7e3bb1315d6b94f Mon Sep 17 00:00:00 2001 From: mehbark Date: Wed, 12 Jul 2023 23:20:19 -0400 Subject: [PATCH] cool bars done enough --- html/bars.tsx | 98 +++++++++++++++++++ ...eople_who_eat_croissants_are_dangerous.tsx | 2 +- 2 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 html/bars.tsx diff --git a/html/bars.tsx b/html/bars.tsx new file mode 100644 index 0000000..e693db2 --- /dev/null +++ b/html/bars.tsx @@ -0,0 +1,98 @@ +import { JSX } from "preact"; +import { Main, render_and_copy } from "./common.tsx"; + +const Bar = ({ + color, + animation_time, + side, +}: { + color: string; + animation_time: number; + side: "left" | "right"; +}): JSX.Element => ( +
+
+
+); + +function coprime(a: number, b: number): boolean { + if (a == b) return false; + for (let i = 2; i < Math.min(a, b); i++) { + if (a % i == 0 && b % i == 0) { + return false; + } + } + return true; +} + +function next_coprime(ns: number[]): number { + if (ns.length == 0) return 2; + + for (let a = ns.at(-1) ?? 0; ; a++) { + let good = true; + for (const b of ns) { + if (!coprime(a, b)) good = false; + } + if (good) return a; + } +} + +function gen_coprimes(to: number): number[] { + if (to <= 0) return []; + if (to == 1) return [2]; + + const xs = gen_coprimes(to - 1); + return [...xs, next_coprime(xs)]; +} + +const BarPair = ({ + color, + animation_time, + num_bars, +}: { + color: string; + animation_time: number; + num_bars: number; +}): JSX.Element => ( +
+ + +
+); + +const Bars = ({ colors }: { colors: string[] }): JSX.Element => ( +
+ {...colors.map((c, i) => ( + + ))} +
+); + +render_and_copy( + +); diff --git a/html/hot_people_who_eat_croissants_are_dangerous.tsx b/html/hot_people_who_eat_croissants_are_dangerous.tsx index 818ac0a..740622f 100644 --- a/html/hot_people_who_eat_croissants_are_dangerous.tsx +++ b/html/hot_people_who_eat_croissants_are_dangerous.tsx @@ -23,7 +23,7 @@ const wheel_style = ( }); const get_delays = (...lengths: number[]): number[] => { - let out = [0]; + const out = [0]; for (const l of lengths) { out.push((out.at(-1) ?? 0) + animation_length(l)); }