Add Bad Apple ASCII intro tile, wire into home grid
Deploy with Docker Compose / deploy (push) Successful in 22s
Deploy with Docker Compose / deploy (push) Successful in 22s
Co-Authored-By: Claude Code <[email protected]>
This commit is contained in:
Binary file not shown.
@@ -10,7 +10,7 @@
|
|||||||
* The widgets do not fetch individually — they all read stores/homeData.js, which
|
* The widgets do not fetch individually — they all read stores/homeData.js, which
|
||||||
* issues one GraphQL query for the whole page.
|
* issues one GraphQL query for the whole page.
|
||||||
*
|
*
|
||||||
* Note which variants are wired up: Intro2 and Gym2, not Intro/Gym.
|
* Note which variants are wired up: Intro3 and Gym2, not Intro/Intro2/Gym.
|
||||||
*/
|
*/
|
||||||
import Timer from "@/components/util/Timer.vue";
|
import Timer from "@/components/util/Timer.vue";
|
||||||
import Time from "@/components/util/Time.vue";
|
import Time from "@/components/util/Time.vue";
|
||||||
@@ -18,7 +18,7 @@ import Radio from "@/components/util/Radio.vue";
|
|||||||
import Chat from "@/components/util/Chat.vue";
|
import Chat from "@/components/util/Chat.vue";
|
||||||
import CommitHistory from "@/components/util/CommitHistory.vue";
|
import CommitHistory from "@/components/util/CommitHistory.vue";
|
||||||
|
|
||||||
import Intro2 from "./Intro2.vue";
|
import Intro3 from "./Intro3.vue";
|
||||||
import Miku from "./Miku.vue";
|
import Miku from "./Miku.vue";
|
||||||
import Stamps from "./Stamps.vue";
|
import Stamps from "./Stamps.vue";
|
||||||
import Listening from "./Listening.vue";
|
import Listening from "./Listening.vue";
|
||||||
@@ -50,7 +50,7 @@ import Bookmarks from "./Bookmarks.vue";
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="page-a4 homeGrid relative bdr-1 border-quaternary">
|
<div class="page-a4 homeGrid relative bdr-1 border-quaternary">
|
||||||
<Intro2 class="intro cell" />
|
<Intro3 class="intro cell" />
|
||||||
<Listening class="listening cell" />
|
<Listening class="listening cell" />
|
||||||
<Stamps class="stamps cell" />
|
<Stamps class="stamps cell" />
|
||||||
<Feed class="feed cell" />
|
<Feed class="feed cell" />
|
||||||
|
|||||||
@@ -0,0 +1,107 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
/**
|
||||||
|
* Intro tile: Bad Apple rendered as ASCII text.
|
||||||
|
*
|
||||||
|
* Source is `vue/public/img/badapple.mp4`, bound via a const rather than written
|
||||||
|
* as a literal `src` because Vite would otherwise try to resolve it as a bundled
|
||||||
|
* asset import; files under public/ are served as-is and must stay unbundled.
|
||||||
|
*
|
||||||
|
* The <video> stays in the DOM (hidden,
|
||||||
|
* muted, looping) because only a playing element decodes frames — drawing a
|
||||||
|
* detached/paused video to a canvas yields nothing.
|
||||||
|
*
|
||||||
|
* Per frame we downscale the video straight into a tiny canvas whose pixel grid
|
||||||
|
* IS the character grid, so the browser's scaler does the averaging for us and
|
||||||
|
* we read back exactly one pixel per character. Sampling is throttled to ~24fps
|
||||||
|
* (source framerate); the grid is only re-measured on resize, since reading
|
||||||
|
* offsetWidth every frame forces a synchronous layout.
|
||||||
|
*/
|
||||||
|
import { ref, useTemplateRef, onMounted, onUnmounted } from "vue";
|
||||||
|
|
||||||
|
const VIDEO_SRC = "/img/badapple.mp4";
|
||||||
|
// Dark -> light. Video is black-and-white, so a short ramp is plenty.
|
||||||
|
const RAMP = " .:-=+*#%@";
|
||||||
|
const CHAR_HEIGHT = 8;
|
||||||
|
const CHAR_WIDTH = CHAR_HEIGHT * 0.55;
|
||||||
|
const FRAME_INTERVAL = 1000 / 24;
|
||||||
|
|
||||||
|
const display = useTemplateRef<HTMLPreElement>("display");
|
||||||
|
const video = useTemplateRef<HTMLVideoElement>("video");
|
||||||
|
const displayText = ref("");
|
||||||
|
|
||||||
|
const canvas = document.createElement("canvas");
|
||||||
|
const ctx = canvas.getContext("2d", { willReadFrequently: true })!;
|
||||||
|
|
||||||
|
let cols = 0;
|
||||||
|
let rows = 0;
|
||||||
|
let rafId = 0;
|
||||||
|
let lastFrame = 0;
|
||||||
|
|
||||||
|
function measure() {
|
||||||
|
const el = display.value;
|
||||||
|
if (!el) return;
|
||||||
|
cols = Math.max(1, Math.floor(el.offsetWidth / CHAR_WIDTH));
|
||||||
|
rows = Math.max(1, Math.floor(el.offsetHeight / CHAR_HEIGHT));
|
||||||
|
canvas.width = cols;
|
||||||
|
canvas.height = rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
function draw(now: number) {
|
||||||
|
rafId = requestAnimationFrame(draw);
|
||||||
|
if (now - lastFrame < FRAME_INTERVAL) return;
|
||||||
|
lastFrame = now;
|
||||||
|
|
||||||
|
const v = video.value;
|
||||||
|
if (!v || v.readyState < 2 || !cols || !rows) return;
|
||||||
|
|
||||||
|
ctx.drawImage(v, 0, 0, cols, rows);
|
||||||
|
const data = ctx.getImageData(0, 0, cols, rows).data;
|
||||||
|
|
||||||
|
let out = "";
|
||||||
|
for (let y = 0; y < rows; y++) {
|
||||||
|
for (let x = 0; x < cols; x++) {
|
||||||
|
const i = (y * cols + x) * 4;
|
||||||
|
// Greyscale source, so the red channel alone is the luminance.
|
||||||
|
out += RAMP[Math.min(RAMP.length - 1, (data[i] * RAMP.length) >> 8)];
|
||||||
|
}
|
||||||
|
if (y < rows - 1) out += "\n";
|
||||||
|
}
|
||||||
|
displayText.value = out;
|
||||||
|
}
|
||||||
|
|
||||||
|
let resizeObserver: ResizeObserver;
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
measure();
|
||||||
|
resizeObserver = new ResizeObserver(measure);
|
||||||
|
resizeObserver.observe(display.value!);
|
||||||
|
// Muted autoplay is the only kind browsers allow without a gesture.
|
||||||
|
video.value?.play().catch(() => {});
|
||||||
|
rafId = requestAnimationFrame(draw);
|
||||||
|
});
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
cancelAnimationFrame(rafId);
|
||||||
|
resizeObserver?.disconnect();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="w-full h-full overflow-hidden bg-black">
|
||||||
|
<video
|
||||||
|
ref="video"
|
||||||
|
:src="VIDEO_SRC"
|
||||||
|
muted
|
||||||
|
loop
|
||||||
|
playsinline
|
||||||
|
preload="auto"
|
||||||
|
class="hidden"
|
||||||
|
/>
|
||||||
|
<pre
|
||||||
|
ref="display"
|
||||||
|
class="w-full h-full m-0 p-0 overflow-hidden bg-black text-white select-none"
|
||||||
|
:style="{ fontSize: CHAR_HEIGHT + 'px', lineHeight: CHAR_HEIGHT + 'px' }"
|
||||||
|
>{{ displayText }}</pre
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
Reference in New Issue
Block a user