Here's a thinking process that leads to the suggested HTML/JS solution:
-
Analyze the Request:
- Goal: Design a "WebGL-based prototyping harness to preview immersive interactions, measure frame budgets, and export accessibility annotations."
- User Persona/Role: "Front-end development engineer and visual designer," "tired of generic rounded corners and shadows," focusing on "Neo-Brutalism" and "Y2K" aesthetics.
- Aesthetic Principles: Raw Typography, Hard Borders, Clashing Colors, Unpolished Look, Glitch Effects, Marquee, Retro UI, Overlapping.
- Tech Stack: Tailwind CSS, GSAP (implied), Canvas/WebGL (core feature), Mix-blend-modes.
- Constraint: Single self-contained HTML file. No external build steps. Think step-by-step first.
-
Conceptualize the "WebGL Prototyping Harness":
- This needs to be a utility tool, but styled according to the user's specific (wild) design preferences.
- Core Functionality:
- WebGL Canvas: The central area to render "immersive interactions" (so a 3D scene where users can manipulate objects).
- Frame Budget Measurement: An FPS counter, frame time graph, or stats overlay.
- Accessibility Annotations: A way to tag elements (like
aria-label or descriptions) and then export them as a JSON or text report.
- UI/UX:
- Layout: Overlapping windows/persistent toolbars (Retro OS feel).
- Visuals: Hard black borders, acidic colors (green, pink, yellow), giant pixelated fonts, marquees.
- Interactions: Glitchy hover effects, maybe a Windows 95/98 style window manager feel but updated with Y2K colors.
-
Step-by-Step Implementation Plan:
-
Structure (HTML):
- Container for the app (full screen).
- Canvas element (WebGL context).
- UI Overlay Layer (absolute positioning, z-index higher). This will hold the "windows" (HUD).
- Windows: Stats Window, Controls/Interaction Window, Accessibility Annotator Window, Export Console.
-
Styling (Tailwind CSS + Custom CSS):
- Use Tailwind via CDN.
- Define custom fonts (maybe a pixel font or Courier New with heavy weight).
- Create utility classes for the "hard border" look (e.g.,
border-2 border-black).
- Colors:
bg-[#ccff00] (acid lime), bg-[#ff00ff] (magenta), bg-[#00ffff] (cyan), bg-white, bg-black.
- Shadows: Hard offset shadows (
shadow-[4px_4px_0px_0px_rgba(0,0,0,1)]) instead of blurry ones.
- Typography: Massive sizes (
text-3xl, text-6xl), uppercase, maybe font-mono or a web font if available (stick to system fonts for single-file constraint: Courier New, Times New Roman).
-
WebGL (JavaScript - Three.js):
- Since I need a robust WebGL scene, I'll use Three.js (via CDN) because raw WebGL is too verbose for a single file prototype.
- Scene: A grid of cubes or a warping mesh that reacts to mouse movement to demonstrate "interactions."
- Interaction: Raycasting. Hovering over objects highlights them.
- Interaction: Dragging objects? (Maybe simple rotation/translation).
- Frame Budget: A loop measuring
delta and updating a graph or simple text.
-
Accessibility Annotations System:
- Mode: Toggle "Edit Mode" in the UI.
- Action: Click on a 3D object. A form/popup appears to add an "Accessibility Label" (text description) and "Role" (button, image, heading).
- Persist: Store annotations in a JavaScript object
Map tied to the Three.js object's UUID.
- Visual feedback: Draw a 2D overlay (HTML div or 2D canvas) on top of the object's screen position to show it has an annotation.
-
Export:
- Button "EXPORT AC.csv" (or JSON). Generates a blob and downloads.
-
Aesthetic Details (Glitch/Marquee):
- Marquee: Use CSS animation
<marquee> or custom @keyframes for the top bar.
- Glitch: CSS
clip-path animations or text-shadow shifts on hover.
-
Refining the代码 (Mental Draft & Iteration):
-
Drafting the WebGL scene:
- Need a scene, camera, renderer.
- Lighting: Ambient + Directional.
- Objects: A floor (grid), and a bunch of floating cubes with different colors.
- Interaction:
mousemove updates a raycaster. If intersect -> change material color/outline.
- Accessibility click:
mousedown on object -> open "Add Annotation" modal.
-
Drafting the UI:
- Use a
fixed top bar: "WEBGL PROTO HARNESS // Y2K EDITION".
- Left panel: "INSPECTOR" (shows selected object info, add accessibility fields).
- Right-bottom panel: "FRAME BUDGET" (simple bar graph made of
divs updating per frame).
- Floating buttons: Hard corners.
-
Implementing the "Hardborder" style:
- Tailwind:
border-2 border-black shadow-[4px_4px_0_#000] bg-white.
- When active/hovered:
translate(1px, 1px) shadow-[2px_2px_0_#000] (pressed effect) or color shift.
-
Accessibility Overlay:
- Need to project 3D coordinates to 2D screen coordinates to draw annotations.
- Approach: In the
requestAnimationFrame loop, iterate through annotated objects, get their vector, project, and update a DOM element's transform.
- If not in edit mode, maybe hide them or show a Badge.
-
Frame Budget Visualization:
- Keep an array of last 60 frame times.
- Render a bar chart using CSS grid or flexbox inside the stats window. Bars change color if frame time > 16ms (red) or < (green).
-
Writing the actual Code (incorporating into the final response structure):
- Setup: HTML5 boilerplate, Tailwind CDN, Three.js CDN, Font Awesome (for icons).
- CSS Overrides: Add animations for marquee, glitch effect classes.
- JS Logic:
- Init Three.js.
- Create random objects.
- Raycaster logic.
- State management:
annotations = {}, selectedObject = null.
- UI Event listeners: "Add Annotation" save, "Export" download.
- Render loop: Update stats, update annotation positions, scene render.
-
Polishing the "Neo-Brutalism/Y2K" Vibe:
- Colors: Electric Lime (#ccff00), Hot Pink (#ff1493), Cyan (#00ffff), Black, White.
- Fonts:
font-mono is good. Use text-shadow to create a " CRT" look.
- Borders: Thick black lines everywhere.
- Yet another touch: A "scanline" overlay using
pointer-events-none.
-
Addressing Specific Requirements:
- Frame Budgets: Add a real-time graph.
- Export Accessibility Annotations: Serialize the map to JSON.
- Immersive Interactions: The WebGL scene itself plus the data-driven annotations.
-
Technical Checks:
- Three.js: Use a version compatible with ESM via
importmap or global script. I'll use the global script https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js for simplicity in a single file.
- Tailwind: Config via script tag to enable arbitrary values? (Tailwind CDN script handles arbitrary values automatically in JIT mode).
- Performance: Ensure the loop is efficient.
-
Refining the Interaction Flow:
- User loads page -> sees chaotic UI + 3D cubes.
- User moves mouse -> Hover effect on cubes.
- User clicks "A11Y MODE" toggle -> Toggles annotation selection.
- User clicks a cube -> Opens "ANNOTATION EDITOR" modal (Neo-brutalist modal, of course).
- User types "Red button" -> Saves.
- Small badge appears floating near the cube.
- User clicks "EXPORT" -> Downloads
a11y_annotations.json.
-
Final Code Assembly: Combine HTML, Tailwind classes, Custom CSS (for the marquee/glitch), and JS logic. (Self-correction: Ensure the modal handles z-index correctly so it's on top).
-
Final Review against prompts:
- Neo-Brutalism? Yes (hard borders, acid colors, raw fonts).
- WebGL based? Yes (Three.js).
- Immersive interactions? Yes (3D manipulation).
- Frame budget? Yes (visual graph).
- Export a11y? Yes (JSON export).
- Single file? Yes.
(Self-Correction during coding): The "hard shadow" (offset black) can sometimes blur at small sizes if not careful, so I'll use pixelated or standard borders. For the "Frame Budget", a simple text "FPS: 60" is boring. I'll create a small bar chart using flex row where each bar represents a frame time. That fits the tech-harness vibe better.
(Glitch Effect): I'll add a CSS class .glitch that applies text-shadow offsets on animation. I'll apply it to the main title.
(Accessibility Overlay): Since the 3D canvas is the background, HTML overlays need to be position: absolute inside a container that matches the canvas size, using pointer-events-none generally, but pointer-events-auto for the badges if they need clicking (optional, but labels need to be visible). For simplicity, the badges are just visual indicators.
Let's build it.
(Output Structure):
- Short intro in Chinese (as requested by the prompt language, but user asked to generate code in response to English prompt? Wait, the user's prompt is English: "Design a WebGL-based prototyping harness..."). The system instruction says: "You are a code expert... Be sure to ensure that the generated code is executable for demonstration." The user's request is in English. I should respond in English (as per "same language as user" rule), but the code comments and explanation in English. However, the system instructions say "Whatever language the user uses in the query, the model must use exactly the same language...". The user used English. So I will respond in English.
Wait, the user prompt is purely English. The system instructions I am given are Chinese ("Design a WebGL-based prototyping harness..."). Actually, the user input is: "Design a WebGL-based prototyping harness to preview immersive interactions, measure frame budgets, and export accessibility annotations." It's English. So I will respond in English.
However, my persona description includes Chinese text about Neo-Brutalism, but that's the role definition. The user asked in English. I will answer in English.
Let's double-check: The user's message is the only content in the prompt. It's English. I will generate the response in English.
Plan:
- Explain the design concept briefly (The "Neo-Brutalist WebGL Prototyping Harness").
- Provide the single HTML file containing everything.
- Explain key features (Neo-Brutalism styling, Three.js scene, Frame Budget graph, Accessibility Annotations system).
Coding details:
- Use
<script src="https://cdn.tailwindcss.com"></script>
- Configure tailwind colors in script tag? I can use arbitrary values
bg-[#D4FF00] etc. That's easier.
- Need a font?
font-family: 'Courier New', monospace; suffices.
- GSAP: Actually, the prompt mentions GSAP for animations. I'll add GSAP via CDN for UI animations (modals popping in, buttons clicking) to satisfy that requirement.
- Three.js: For the 3D.
- Canvas for frame budget graph? I can use pure DOM elements (divs) which is easier to style with Tailwind (a "histogram"). Or a canvas. Let's use DOM elements for the bars to keep it simple and align with the "hard border" aesthetic.
Let's write the code.
-
HTML Structure:
#app: relative, w-full h-screen overflow-hidden bg-[#f0f0f0] (light gray for contrast, or white).
#canvas-container: absolute top-0 left-0 w-full h-full z-0.
#ui-layer: absolute top-0 left-0 w-full h-full z-10 pointer-events-none.
- Inside UI layer, pointer-events-auto panels.
- Top Bar:
h-16 bg-black text-white flex items-center px-4 border-b-4 border-white ... Actually stick to Yellow/Black.
- Left Panel: Stats.
- Right Panel: Controls / A11y.
- Overlay for active annotations.
-
Styling:
.hard-border: border-2 border-black shadow-[4px_4px_0_0_#000]
.hard-border:hover: translate(2px,2px) shadow-[2px_2px_0_0_#000]
- Glitch keyframes.
-
Three.js Logic:
- Scene, Camera (Perspective), Renderer (antialias: true).
- Objects: Array of cubes with random positions/rotations and distinct colors (acid palette).
- Lights: Hemisphere + Directional.
- Interaction:
mousemove -> raycast. Update intersectedObject.
- Highlight: If intersect, set material emissive or wireframe overlay? Use a black outline helper? Or simply change color to something high contrast. Let's use
emissive property to pop.
mousedown: If intersect, trigger "Select".
- Selection: Opens A11y panel. If "A11y Edit Mode" is on, we can assign metadata.
-
A11y System:
- Data structure:
{'uuid': {'label': '...', 'role': '...'}}
- Visual: An HTML div floating on screen, anchored to the projected position. Class:
bg-acid-yellow border-black border-2 text-black font-bold px-2.
-
Frame Budget:
frameTimes array (push delta, shift if length > 30).
- Max frame time cap (e.g., 33ms = 30fps).
- Height of bar =
(value / max) * 100%. Color: green if < 16ms, yellow < 30ms, red > 30ms.
-
Export:
Blob creation -> URL.createObjectURL -> download click.
Let's assemble.
Refining the "Unpolished Look" and "Glitch":
I will add a simple JS function that randomly offsets the position of the top bar text "WEBGL HARNESS // SYSTEM READY" for a few milliseconds every few seconds to simulate a signal instability. And a CSS text-shadow animation.
Icons: Use SVG strings directly or FontAwesome CDN. I'll use FontAwesome CDN (<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">) for convenience.
Let's go.
(Self-Correction during drafting code):
The prompt asks for "Neo-Brutalism" and "Y2K". Y2K often implies bubbly, translucent, but I'll stick to the prompt's specific constraints: "Raw Typography, High Contrast Borders, Clashing Colors, Unpolished."
I will ensure the layout feels like a "tool" not a website.
Final Code Structure:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Neo-Brutalist WebGL Harness</title>
<!-- Tailwind, Three.js, GSAP, FontAwesome -->
</head>
<body class="font-mono overflow-hidden bg-white text-black">
<!-- Canvas -->
<canvas id="glCanvas"></canvas>
<!-- UI Overlay -->
<div id="ui-layer" class="absolute inset-0 pointer-events-none">
<!-- Header Marquee -->
<div class="w-full bg-[#FF00FF] border-b-4 border-black text-white overflow-hidden">
<marquee behavior="scroll" direction="left" class="text-2xl font-bold tracking-tighter uppercase">
<i class="fas fa-triangle-exclamation"></i> WARNING: FRAME BUDGET CRITICAL // IMMERSIVE PROTO HARNESS v0.1 // NEO-BRUTALIST EDITION <i class="fas fa-bolt"></i>
</marquee>
</div>
<!-- panels with pointer-events-auto -->
<!-- ... -->
</div>
<!-- Script -->
<script>
// Logic here
</script>
</body>
</html>
I will implement the A11y panel as a "floating window" that can be dragged? That adds complexity. Keep it static resposive. Left side: Stats, Right side: Inspector.
Let's finalize the features:
- 3D Scene: Grid of cubes. Hovering causes a "shock" effect (glitch scale).
- Stats: FPS history bar chart.
- A11y:
- Toggle "A11y Edit Mode" (switch).
- Object clicked -> Form opens (Label input, Role select [img, button, input]).
- Save -> Floating label appears near object in 3D.
- Export: Button that dumps JSON.
Let's write it.
Here is a complete, self-contained HTML solution. It implements a Neo-Brutalist / Y2K styled WebGL prototyping tool using Three.js for the scene, Tailwind CSS for the chaotic UI, GSAP for snappy animations, and a functional accessibility annotation system with frame budget monitoring.
Key Features
- Aesthetic: Hard borders (
border-2), acidic colors (#ccff00, #ff00ff), raw system fonts (Courier New), and a persistent marquee.
- WebGL Core: A 3D scene with interactive cubes. Hovering triggers a "glitch" visual effect. Objects can be selected.
- Frame Budget Monitor: A real-time histogram visualizing frame times (ms) over the last 60 frames, color-coded by performance (Green < 16ms, Yellow < 33ms, Red > 33ms).
- Accessibility Annotations:
- Enable "A11Y EDIT MODE".
- Click any 3D object to assign a
label and role.
- A floating "badge" appears in world space attached to the object.
- Export functionality generates a downloadable JSON file with 3D positions (world coordinates) and metadata.
Save the following code as an .html file (e.g., harness.html) and open it in any modern browser.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>NEO-BRUTALIST WEBGL HARNESS</title>
<!-- Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Three.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<!-- GSAP for animations -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script>
<!-- FontAwesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<!-- Custom Config for Tailwind to extend theme -->
<script>
tailwind.config = {
theme: {
extend: {
fontFamily: {
mono: ['"Courier New"', 'Courier', 'monospace'],
display: ['"Times New Roman"', 'Times', 'serif'],
},
colors: {
acid: {
lime: '#ccff00',
magenta: '#ff00ff',
cyan: '#00ffff',
yellow: '#ffee00',
},
void: '#000000',
paper: '#ffffff'
},
boxShadow: {
'hard': '4px 4px 0px 0px rgba(0,0,0,1)',
'hard-sm': '2px 2px 0px 0px rgba(0,0,0,1)',
'hard-lg': '6px 6px 0px 0px rgba(0,0,0,1)',
},
animation: {
'glitch': 'glitch 0.5s infinite linear alternate-reverse',
'marquee': 'marquee 15s linear infinite',
'pulse-hard': 'pulse-hard 1s infinite',
},
keyframes: {
glitch: {
'0%': { transform: 'translate(0)' },
'20%': { transform: 'translate(-2px, 2px)' },
'40%': { transform: 'translate(-2px, -2px)' },
'60%': { transform: 'translate(2px, 2px)' },
'80%': { transform: 'translate(2px, -2px)' },
'100%': { transform: 'translate(0)' },
},
marquee: {
'0%': { transform: 'translateX(0%)' },
'100%': { transform: 'translateX(-100%)' },
},
'pulse-hard': {
'0%, 100%': { transform: 'scale(1)' },
'50%': { transform: 'scale(0.98)' },
}
}
}
}
}
</script>
<style>
body {
cursor: crosshair;
overflow: hidden;
}
/* CRT Scanline Effect Overlay */
.scanlines {
background: linear-gradient(
to bottom,
rgba(255,255,255,0),
rgba(255,255,255,0) 50%,
rgba(0,0,0,0.1) 50%,
rgba(0,0,0,0.1)
);
background-size: 100% 4px;
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
pointer-events: none;
z-index: 9999;
}
/* For the marquee content duplication */
.marquee-content {
display: inline-block;
white-space: nowrap;
padding-left: 100%;
animation: marquee 20s linear infinite;
}
/* Custom Scrollbar for that raw look */
::-webkit-scrollbar {
width: 16px;
background: #fff;
border-left: 2px solid #000;
}
::-webkit-scrollbar-thumb {
background: #000;
border: 2px solid #fff;
}
</style>
</head>
<body class="font-mono text-black bg-paper selection:bg-acid-lime selection:text-black">
<!-- Scanline Texture -->
<div class="scanlines"></div>
<!-- WebGL Canvas Container -->
<div id="canvas-container" class="absolute inset-0 z-0 bg-gray-100">
<canvas id="glCanvas"></canvas>
</div>
<!-- UI Overlay Layer -->
<div id="ui-layer" class="absolute inset-0 z-50 pointer-events-none flex flex-col justify-between p-4">
<!-- Top Header Bar -->
<header class="w-full bg-acid-magenta border-b-4 border-black p-2 pointer-events-auto relative shadow-hard">
<div class="flex justify-between items-center">
<div class="text-xl font-bold tracking-tighter text-white uppercase flex items-center gap-2">
<i class="fas fa-cube animate-pulse"></i>
<span class="bg-black text-acid-lime px-2 border border-white">PROTO</span>
HARNESS <span class="animate-glitch">V.9Y2K</span>
</div>
<div class="text-sm font-bold bg-white border-2 border-black px-3 py-1 shadow-hard-sm hidden md:block">
<i class="fas fa-wrench"></i> RENDER: WEBGL2 // TARGET: 60FPS
</div>
</div>
<!-- Scrolling Marquee -->
<div class="mt-2 overflow-hidden h-8 bg-black text-acid-lime text-xs border-y-2 border-white flex items-center font-bold uppercase">
<div class="marquee-content">
SYSTEM INITIALIZED... WAITING FOR INPUT... MEASURING FRAME BUDGET... EXPORT READY... ACCESSIBILITY MODE: <span id="a11y-status">DISABLED</span>... GLITCH DETECTOR: ACTIVE...
</div>
</div>
</header>
<!-- Main Content Grid -->
<div class="flex-1 flex gap-4 mt-4 min-h-0">
<!-- Left Panel: Frame Budget (Stats) -->
<aside class="w-64 pointer-events-auto bg-white border-4 border-black shadow-hard flex flex-col">
<div class="bg-acid-cyan border-b-4 border-black p-2 font-bold text-lg flex justify-between items-center">
<span><i class="fas fa-chart-line"></i> BUDGET</span>
<span id="fps-display" class="bg-black text-white px-2">60</span>
</div>
<div class="p-4 flex-1 flex flex-col gap-4">
<div>
<h3 class="text-xs font-bold uppercase mb-2">Frame Time (ms)</h3>
<div id="frame-graph" class="w-full h-24 flex items-end gap-1 border-b-2 border-black">
<!-- Bars injected by JS -->
</div>
<div class="flex justify-between text-[10px] mt-1 text-gray-500 uppercase">
<span>0ms</span>
<span>16ms (60fps)</span>
<span>33ms (30fps)</span>
</div>
</div>
<div class="border-t-2 border-black pt-4">
<h3 class="text-xs font-bold uppercase mb-2">Instructions</h3>
<ul class="text-xs space-y-2">
<li><span class="text-acid-magenta font-bold">[LMB]</span> Rotate View</li>
<li><span class="text-acid-magenta font-bold">[HOVER]</span> Trigger Glitch</li>
<li><span class="text-acid-magenta font-bold">[A11Y MODE]</span> Edit Object Data</li>
</ul>
</div>
<div class="mt-auto border-t-2 border-black pt-2">
<button id="export-btn" class="w-full bg-acid-yellow border-2 border-black py-2 font-bold text-sm shadow-hard hover:translate-[2px_2px] hover:shadow-none active:translate-0 transition-all uppercase">
<i class="fas fa-download"></i> Export Annotations
</button>
</div>
</div>
</aside>
<!-- Center Area: Interactive Controls (Empty space mostly to show canvas) -->
<main class="flex-1 pointer-events-auto flex items-center justify-center relative">
<!-- Floating A11y Status Box -->
<div id="a11y-panel" class="absolute top-4 right-4 bg-white/90 border-4 border-black shadow-hard p-4 w-72 z-50 transition-opacity duration-300">
<div class="flex justify-between items-center mb-3">
<h2 class="text-lg font-bold bg-black text-white px-2 uppercase">A11y Inspector</h2>
<div class="flex items-center gap-2">
<label class="relative inline-block w-12 h-6 cursor-pointer">
<input type="checkbox" id="a11y-toggle" class="sr-only peer">
<div class="w-full h-full bg-gray-300 border-2 border-black rounded-none peer-focus:outline-none transition-colors peer-checked:bg-acid-lime"></div>
<div class="absolute top-0 left-0 bg-black h-6 w-6 border-2 border-black transition-transform peer-checked:translate-x-6"></div>
</label>
</div>
</div>
<div id="a11y-forms" class="hidden space-y-3">
<div class="border-2 border-black p-2 bg-acid-yellow/20">
<p class="text-xs font-bold uppercase mb-1">Selected Object UUID</p>
<p id="selected-uuid" class="text-xs font-mono break-all">--</p>
</div>
<div>
<label class="block text-xs font-bold uppercase">Label (for Screen Readers)</label>
<input id="input-label" type="text" class="w-full mt-1 border-2 border-black p-2 font-mono text-sm bg-white focus:bg-acid-cyan focus:outline-none" placeholder="e.g. Red Submit Button">
</div>
<div>
<label class="block text-xs font-bold uppercase">Role</label>
<select id="input-role" class="w-full mt-1 border-2 border-black p-2 font-mono text-sm bg-white focus:bg-acid-cyan focus:outline-none">
<option value="button">Button</option>
<option value="img">Image</option>
<option value="heading">Heading</option>
<option value="text">Generic Text</option>
</select>
</div>
<button id="save-annotation" class="w-full bg-acid-magenta text-white border-2 border-black py-2 font-bold shadow-hard hover:translate-[2px_2px] hover:shadow-none active:translate-0 transition-all uppercase">
Save Tag
</button>
</div>
<div id="a11y-placeholder" class="text-center text-sm font-bold p-4 border-2 border-dashed border-black">
Enable A11Y Mode to Tag Objects
</div>
</div>
</main>
<!-- Right Panel: Log / System Output -->
<aside class="w-64 pointer-events-auto bg-white border-4 border-black shadow-hard flex flex-col">
<div class="bg-acid-yellow border-b-4 border-black p-2 font-bold text-lg flex items-center justify-center">
<i class="fas fa-terminal"></i> LOG
</div>
<div class="flex-1 p-0 overflow-hidden relative">
<div class="absolute inset-0 overflow-y-auto p-2 font-mono text-xs space-y-2 bg-gray-50 border-t-2 border-black" id="system-log">
<div class="text-green-700">[SYSTEM] WebGL Context Created</div>
<div class="text-green-700">[SYSTEM] Harness Loaded</div>
<div class="text-blue-700">[INFO] Rendering Loop Started</div>
</div>
</div>
</aside>
</div>
<!-- Bottom Bar -->
<footer class="w-full bg-void text-white mt-2 pt-2 pb-1 pointer-events-auto border-t-4 border-black shadow-hard">
<div class="flex justify-between items-end text-[10px] uppercase font-bold">
<span class="bg-acid-lime text-black px-2 py-1">Node: <span id="node-id">NEO-01</span></span>
<span class="italic font-serif">
"Design is not just what it looks like and feels like. Design is how it works."
</span>
<span class="text-acid-cyan">MEM: <span id="mem-display">--</span> MB</span>
</div>
</footer>
</div>
<!-- JavaScript Application Logic -->
<script>
// --- 1. CONFIG & STATE ---
const state = {
a11yMode: false,
selectedObject: null,
frameTimeHistory: new Array(60).fill(16),
lastFrameTime: 0,
annotations: {}, // Map: uuid -> { label, role }
memoryUsage: 0
};
// DOM Elements
const dom = {
fps: document.getElementById('fps-display'),
graph: document.getElementById('frame-graph'),
a11yToggle: document.getElementById('a11y-toggle'),
a11yForms: document.getElementById('a11y-forms'),
a11yPlaceholder: document.getElementById('a11y-placeholder'),
a11yStatus: document.getElementById('a11y-status'),
selectedUuid: document.getElementById('selected-uuid'),
inputLabel: document.getElementById('input-label'),
inputRole: document.getElementById('input-role'),
saveBtn: document.getElementById('save-annotation'),
exportBtn: document.getElementById('export-btn'),
systemLog: document.getElementById('system-log'),
memDisplay: document.getElementById('mem-display'),
canvasContainer: document.getElementById('canvas-container')
};
// --- 2. THREE.JS SCENE SETUP ---
const canvas = document.getElementById('glCanvas');
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf0f0f0); // Light gray paper background
// Add a grid floor
const gridHelper = new THREE.GridHelper(50, 50, 0x000000, 0x000000);
gridHelper.material.opacity = 0.1;
gridHelper.material.transparent = true;
scene.add(gridHelper);
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.set(10, 10, 10);
camera.lookAt(0, 0, 0);
const renderer = new THREE.WebGLRenderer({ canvas: canvas, antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
// Lighting
const ambientLight = new THREE.AmbientLight(0xffffff, 0.6);
scene.add(ambientLight);
const dirLight = new THREE.DirectionalLight(0xffffff, 0.8);
dirLight.position.set(10, 20, 10);
dirLight.castShadow = true;
scene.add(dirLight);
// --- 3. INTERACTIVE OBJECTS ---
const objects = [];
const geometryBox = new THREE.BoxGeometry(2, 2, 2);
// Acid color palette
const colors = [0xccff00, 0xff00ff, 0x00ffff, 0xffee00, 0xff3333, 0x3333ff];
// Generate random cubes
for (let i = 0; i < 30; i++) {
const color = colors[Math.floor(Math.random() * colors.length)];
const material = new THREE.MeshStandardMaterial({
color: color,
roughness: 0.4,
metalness: 0.1
});
const cube = new THREE.Mesh(geometryBox, material);
// Random position avoiding center
const range = 15;
cube.position.x = (Math.random() - 0.5) * range;
cube.position.z = (Math.random() - 0.5) * range;
cube.position.y = Math.random() * 5 + 1;
cube.castShadow = true;
cube.receiveShadow = true;
// Store original rotation for animation
cube.userData = {
id: Math.random().toString(36).substr(2, 9),
rotSpeed: {
x: (Math.random() - 0.5) * 0.02,
y: (Math.random() - 0.5) * 0.02
},
originalColor: color,
isGlitching: false
};
scene.add(cube);
objects.push(cube);
}
// Raycaster
const raycaster = new THREE.Raycaster();
const mouse = new THREE.Vector2();
// --- 4. ACCESSIBILITY ANNOTATION UI OVERLAY ---
// We need a container for 2D labels that float over 3D elements
const labelContainer = document.createElement('div');
labelContainer.className = 'absolute inset-0 pointer-events-none z-50 overflow-hidden';
dom.canvasContainer.appendChild(labelContainer);
function createOrUpdateLabel(object) {
// Check if we already have a label element for this object
let el = document.getElementById(`label-${object.uuid}`);
const ann = state.annotations[object.uuid];
if (ann) {
// If annotation exists, ensure label is visible
if (!el) {
el = document.createElement('div');
el.id = `label-${object.uuid}`;
el.className = 'absolute px-3 py-1 bg-acid-lime border-2 border-black shadow-hard font-bold text-xs transform -translate-x-1/2 -translate-y-full whitespace-nowrap z-50 pointer-events-auto cursor-pointer hover:bg-white';
// Add delete functionality? Maybe simpler: click to edit? Let's keep simple.
el.innerText = `${ann.role.toUpperCase()}: ${ann.label}`;
el.style.borderRadius = '0';
labelContainer.appendChild(el);
}
} else {
// Remove if exists but no annotation
if (el) el.remove();
}
}
function updateLabelPositions() {
// Temp vector for projection
const vector = new THREE.Vector3();
objects.forEach(obj => {
const ann = state.annotations[obj.uuid];
if (ann) {
const el = document.getElementById(`label-${obj.uuid}`);
if (el) {
vector.setFromMatrixPosition(obj.matrixWorld);
// Offset slightly above object
vector.y += 1.5;
vector.project(camera);
const x = (vector.x * .5 + .5) * canvas.clientWidth;
const y = (-(vector.y * .5) + .5) * canvas.clientHeight;
// Cull if behind camera or too far
if (vector.z > 1) {
el.style.display = 'none';
} else {
el.style.display = 'block';
el.style.left = `${x}px`;
el.style.top = `${y}px`;
}
}
}
});
}
// --- 5. INPUT HANDLING ---
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
window.addEventListener('mousemove', (event) => {
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
});
window.addEventListener('mousedown', (event) => {
// Only process if clicking on canvas (not UI)
if (event.target.closest('.pointer-events-auto')) return;
raycaster.setFromCamera(mouse, camera);
const intersects = raycaster.intersectObjects(objects);
if (intersects.length > 0) {
const object = intersects[0].object;
handleObjectClick(object);
} else {
// Clicking void deselects
if (state.a11yMode) {
deselectObject();
}
}
});
function handleObjectClick(object) {
if (!state.a11yMode) {
// If not in A11y mode, just flash a highlight visual feedback (Glitch)
gsap.to(object.scale, { x: 1.2, y: 1.2, z: 1.2, duration: 0.1, yoyo: true, repeat: 1 });
return;
}
selectObject(object);
}
function selectObject(object) {
// Deselect previous
if (state.selectedObject) {
state.selectedObject.material.emissive.setHex(0x000000);
}
state.selectedObject = object;
// Highlight selection
object.material.emissive.setHex(0x555555);
// Update UI
dom.selectedUuid.textContent = object.uuid || object.id; // Ensure unique
const existing = state.annotations[object.uuid];
dom.inputLabel.value = existing ? existing.label : '';
dom.inputRole.value = existing ? existing.role : 'button';
dom.a11yForms.classList.remove('hidden');
dom.a11yPlaceholder.classList.add('hidden');
}
function deselectObject() {
if (state.selectedObject) {
state.selectedObject.material.emissive.setHex(0x000000);
}
state.selectedObject = null;
dom.a11yForms.classList.add('hidden');
dom.a11yPlaceholder.classList.remove('hidden');
}
// A11y Toggle Switch
dom.a11yToggle.addEventListener('change', (e) => {
state.a11yMode = e.target.checked;
dom.a11yStatus.textContent = state.a11yMode ? "ACTIVE" : "DISABLED";
dom.a11yStatus.parentElement.classList.toggle('text-acid-lime', state.a11yMode);
dom.a11yStatus.parentElement.classList.toggle('text-gray-500', !state.a11yMode);
console.log(`[A11Y] Mode ${state.a11yMode ? 'enabled' : 'disabled'}`);
if (!state.a11yMode) {
deselectObject();
} else if (state.selectedObject) {
dom.a11yForms.classList.remove('hidden');
dom.a11yPlaceholder.classList.add('hidden');
}
});
// Save Annotation
dom.saveBtn.addEventListener('click', () => {
if (!state.selectedObject) return;
const label = dom.inputLabel.value.trim();
const role = dom.inputRole.value;
if (!label) {
alert("Please enter a label (Neo-Brutalism requires all data)!");
return;
}
state.annotations[state.selectedObject.uuid] = { label, role };
createOrUpdateLabel(state.selectedObject);
// Visual feedback on button
gsap.to(dom.saveBtn, { backgroundColor: '#00ff00', duration: 0.1, yoyo: true, repeat: 1, onComplete: () => {
dom.saveBtn.style.backgroundColor = ''; // reset
}});
log(`[A11Y] Tagged ${state.selectedObject.uuid} as '${role}'`);
});
// Export Annotations
dom.exportBtn.addEventListener('click', () => {
const exportData = {
timestamp: new Date().toISOString(),
frameBudgetConfig: { targetFPS: 60 },
annotations: []
};
objects.forEach(obj => {
if (state.annotations[obj.uuid]) {
const pos = obj.position;
exportData.annotations.push({
uuid: obj.uuid,
label: state.annotations[obj.uuid].label,
role: state.annotations[obj.uuid].role,
position: { x: pos.x.toFixed(2), y: pos.y.toFixed(2), z: pos.z.toFixed(2) }
});
}
});
const blob = new Blob([JSON.stringify(exportData, null, 2)], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `a11y_annotations_${Date.now()}.json`;
a.click();
URL.revokeObjectURL(url);
log("[EXPORT] Annotations downloaded as JSON");
});
function log(msg) {
const time = new Date().toLocaleTimeString();
const div = document.createElement('div');
div.innerHTML = `<span class="text-gray-500">[${time}]</span> <span class="${msg.includes('ERROR') || msg.includes('WARN') ? 'text-red-600' : 'text-blue-700'}">${msg}</span>`;
dom.systemLog.prepend(div);
// Limit log size
if (dom.systemLog.children.length > 50) {
dom.systemLog.removeChild(dom.systemLog.lastChild);
}
}
// --- 6. FRAME BUDGET SYSTEM ---
function updateStats() {
const now = performance.now();
const delta = now - state.lastFrameTime;
state.lastFrameTime = now;
// Smooth FPS
const fps = 1000 / delta;
dom.fps.textContent = Math.round(fps);
// Update History
state.frameTimeHistory.push(delta);
state.frameTimeHistory.shift();
// Draw Graph
dom.graph.innerHTML = '';
const maxVal = 50; // max ms to display (infinity bar)
state.frameTimeHistory.forEach((val, idx) => {
const bar = document.createElement('div');
const pct = Math.min((val / maxVal) * 100, 100);
bar.style.width = '4px';
bar.style.height = `${pct}%`;
bar.style.alignSelf = 'flex-end';
// Color code
if (val < 16) bar.style.backgroundColor = '#00cc00'; // Green
else if (val < 33) bar.style.backgroundColor = '#ffcc00'; // Yellow
else bar.style.backgroundColor = '#ff0000'; // Red
// Hard border
bar.classList.add('border-r', 'border-black');
dom.graph.appendChild(bar);
});
// Memory (if available)
if (performance.memory) {
const mb = Math.round(performance.memory.usedJSHeapSize / 1048576);
dom.memDisplay.textContent = mb;
}
}
// --- 7. ANIMATION LOOP ---
function animate(time) {
requestAnimationFrame(animate);
const delta = time - state.lastFrameTime;
// Object Rotations
objects.forEach(obj => {
obj.rotation.x += obj.userData.rotSpeed.x;
obj.rotation.y += obj.userData.rotSpeed.y;
});
// Raycasting for Hover Effects
raycaster.setFromCamera(mouse, camera);
const intersects = raycaster.intersectObjects(objects);
// Reset all hover states
objects.forEach(obj => {
if (obj !== state.selectedObject) {
// If not glitching, reset color
if (!obj.userData.isGlitching) {
obj.material.color.setHex(obj.userData.originalColor);
}
}
});
if (intersects.length > 0) {
const hovered = intersects[0].object;
if (hovered !== state.selectedObject) {
// Glitch effect: flicker color and scale
hovered.userData.isGlitching = true;
hovered.material.color.setHex(0x000000); // turn black
// Random scale micro-jitters using Math.random since we aren't using GSAP for per-frame heavy jitter
hovered.scale.set(
1 + (Math.random() * 0.2 - 0.1),
1 + (Math.random() * 0.2 - 0.1),
1 + (Math.random() * 0.2 - 0.1)
);
// If mouse moves off, we need to reset. Handled next frame if not in intersects.
}
} else {
objects.forEach(obj => {
if (obj.userData.isGlitching) {
obj.userData.isGlitching = false;
obj.scale.set(1, 1, 1);
if (obj !== state.selectedObject) {
obj.material.color.setHex(obj.userData.originalColor);
}
}
});
}
// Update Label Positions
updateLabelPositions();
// Render
renderer.render(scene, camera);
// Update Stats independently of frame rate (every 10th frame to save DOM thrashing? Or every frame? Let's do every frame but it's fine for few bars)
updateStats();
}
// Initialize Random Node ID
document.getElementById('node-id').textContent = 'NEO-' + Math.floor(Math.random() * 999);
// Start Loop
animate(0);
log("INFO: WebGL Prototyping Harness Ready");
log("WARN: Unpolished Aesthetic Active");
</script>
</body>
</html>