feat: H I line age counter funny thing lol ahahahhahahahah

pull/1/head
Elias Almqvist 1 year ago
parent 97c2f65eb8
commit cbe31bbac8
No known key found for this signature in database
GPG Key ID: E31A99CE3E75A158
  1. 10
      src/app/page.tsx
  2. 96
      src/components/age.tsx

@ -1,6 +1,6 @@
import ThingCurve from "@/components/3d/curves/thing"; import ThingCurve from "@/components/3d/curves/thing";
import RenderedSection from "@/components/3d/renderedsection"; import RenderedSection from "@/components/3d/renderedsection";
import AgeDisplay from "@/components/age"; import AgeHCyclesDisplay from "@/components/age";
import { import {
Card, Card,
CardContent, CardContent,
@ -9,7 +9,6 @@ import {
CardTitle, CardTitle,
} from "@/components/ui/card"; } from "@/components/ui/card";
export default function Home() { export default function Home() {
return ( return (
<> <>
@ -24,9 +23,10 @@ export default function Home() {
<CardTitle>Elias Almqvist</CardTitle> <CardTitle>Elias Almqvist</CardTitle>
<CardDescription className="pl-0 space-y-4"> <CardDescription className="pl-0 space-y-4">
<p> <p>
I am a {<AgeDisplay precision={10} />}-year-old <span className="font-bold">human-</span>{" "} I am a {<AgeHCyclesDisplay precision={6} />}{" "}
founder, engineer, and hacker with a passion for CS, physics, <span className="font-bold">hydrogen-line-cycles</span> old{" "}
and mathematics. <span className="font-bold">human-</span> founder, engineer, and
hacker with a passion for CS, physics, and mathematics.
</p> </p>
<p> <p>
Currently working on ingenuity. Most of my projects are Currently working on ingenuity. Most of my projects are

@ -1,11 +1,9 @@
"use client"; "use client";
import { cn } from "@/lib/utils";
import { useCallback, useEffect, useRef, useState } from "react"; import { useCallback, useEffect, useRef, useState } from "react";
type AgeDisplayProps = { const hydrogenLineFrequency_Hz = 1420.405751768 * 10 ** 6;
className?: string;
precision?: number;
};
function getAge() { function getAge() {
let birth = 1050019200; let birth = 1050019200;
@ -13,35 +11,83 @@ function getAge() {
return now - birth; return now - birth;
} }
function secondsToYears(secs: number, precision: number) { function secondsToHydrogenLineCycles(secs: number) {
let years = secs / 31556952; return secs * hydrogenLineFrequency_Hz;
return years.toFixed(precision);
} }
const AgeDisplay: React.FC<AgeDisplayProps> = ({ type FormatBigNumberProps = {
num: number;
precision: number;
className?: string;
};
const FormatBigNumber: React.FC<FormatBigNumberProps> = ({
num,
precision,
className, className,
precision = 2,
}) => { }) => {
const ref = useRef<HTMLSpanElement>(null); const suffixes = [
"",
"K",
"M",
"Bn",
"T",
"Q",
"Qt",
"Sx",
"Sp",
"O",
"N",
"D",
"Ud",
"Dd",
"Td",
"Qad",
"Qid",
"Sd",
"Sed",
"Od",
"Nod",
"Vg",
];
let exponent = Math.floor(Math.log10(num) / 3);
exponent = Math.min(exponent, suffixes.length - 1);
const base = num / Math.pow(10, exponent * 3);
const formattedBase = base.toFixed(precision);
const suffix = suffixes[exponent];
const anim = useCallback(() => { return (
if (!ref.current) { <span className={cn("inline-flex flex-row space-x-0.5 mr-1", className)}>
return; <span className="inline-block">{formattedBase}</span>
} <span className="inline-block italic">{suffix}</span>
ref.current.textContent = secondsToYears(getAge(), precision); </span>
}, []) );
};
type AgeHCyclesDisplayProps = {
className?: string;
precision?: number;
};
const AgeHCyclesDisplay: React.FC<AgeHCyclesDisplayProps> = ({
className,
precision = 2,
}) => {
const [cycles, setCycles] = useState<number>(0);
useEffect(() => { useEffect(() => {
const animFrame = requestAnimationFrame(() => { const interval = setInterval(() => {
anim(); setCycles(secondsToHydrogenLineCycles(getAge()));
}); }, 400);
return () => { return () => clearInterval(interval);
cancelAnimationFrame(animFrame); });
};
}, [getAge, ref.current]);
return <span ref={ref} className={className}>??</span>; return (
<FormatBigNumber num={cycles} precision={precision} className={className} />
);
}; };
export default AgeDisplay; export default AgeHCyclesDisplay;

Loading…
Cancel
Save