A portfolio-style reaction timer game built as a single static HTML file using vanilla JavaScript and Three.js.
The project is designed to demonstrate:
- clean frontend engineering
- precise timing logic with
performance.now() - state-driven UI updates
- responsive layout and UX polish
- animated 3D graphics in the browser
Reaction Forge is a browser game where the player starts a round, waits for a random signal, and then reacts as quickly as possible.
The game includes:
- random delay before the stimulus appears
- false start detection
- reaction-time measurement in milliseconds
- session statistics
- recent-attempt history
- a live Three.js scene used as the visual centrepiece of the game
This revised version uses a 3D sphere as the main scene object and removes the three informational boxes that previously showed tech, timing, and stimulus details.
reaction-game-v2.html— the complete application in one fileREADME-reaction-game.md— this documentation file
- Start / Stop / Reset controls
- Random stimulus timing between 1 and 5 seconds
- Accurate reaction timing using
performance.now() - False start detection when the player clicks too early
- Immediate result display after a valid reaction
- Best reaction time
- Average reaction time
- Attempt count
- Recent attempts panel with simple performance labels
- Built with Three.js
- Central animated 3D sphere
- Orbit rings, sparks, lighting, and animated motion
- Visual state changes for:
- idle
- waiting
- ready
- result
- false start
- error
- Click-responsive sphere movement inside the stage area
- Responsive layout for desktop and mobile
- Keyboard support
- Focusable stage area
- Live region messaging for status updates
- Strong contrast and modern UI styling
- Start button: begins a new round
- Stop button: stops the current round
- Reset button: clears all stats and history
- Click the stage when the signal is active to record your reaction time
- Enter: start a round when Start is available
- Space: react during the active signal
- Esc: stop the current round
- The page loads in the Idle state.
- The player presses Start.
- The game enters the Waiting state.
- A random delay is generated between 1000 ms and 5000 ms.
- The game switches to the Ready state.
- The player clicks or presses Space.
- The game records the reaction time and shows the result.
- Stats and recent attempts are updated.
If the player clicks too early during the waiting phase, the game triggers a False Start state.
The game uses a simple state model:
idlewaitingreadyresultfalse-starterror
Each state updates:
- the status chip
- the main display text
- the instruction text
- button availability
- the visual treatment of the Three.js scene
This keeps gameplay logic and UI behavior predictable and easier to maintain.
Reaction measurement uses:
performance.now()This gives higher-precision timing than Date.now() and is better suited for millisecond-sensitive interaction.
The stimulus delay is generated in this range:
1000 ms to 5000 msThat prevents the player from anticipating a fixed pattern.
The 3D scene includes:
PerspectiveCamera- ambient, directional, and point lighting
- a main sphere mesh
- a wireframe core sphere
- orbit rings
- animated spark elements
- a render loop driven by
requestAnimationFrame
The code also includes cleanup logic for:
- animation frames
- resize observers
- geometries
- materials
- renderer disposal
- Background:
#0F172A - Surface:
#1E293B - Text:
#F1F5F9 - Secondary text:
#94A3B8 - Ready:
#10B981 - Waiting:
#F59E0B - Result:
#3B82F6 - Error:
#EF4444
- Inter for UI and data
- Outfit for headings
Double-click the HTML file:
reaction-game-v2.html
or right-click it and choose Open With your browser.
A local server is often better during development.
python3 -m http.serverThen open:
http://localhost:8000
The project loads Three.js from a CDN:
https://unpkg.com/three@0.164.1/build/three.min.jsThat means:
- the page can still load locally
- but the 3D scene needs an internet connection unless Three.js is bundled or hosted locally
If Three.js fails to load, the game falls back to a non-3D mode and still remains playable.
Good next enhancements for a stronger portfolio version:
- add a visible FPS/performance-safe mode toggle
- add subtle sound effects with mute control
- add difficulty presets
- add a post-result micro chart of recent attempts
- move Three.js to a local module build instead of CDN
- add automated tests for core game-state transitions
- improve the click-to-sphere coordinate mapping for tighter visual accuracy
This project is suitable as a portfolio piece for showing:
- JavaScript fundamentals
- DOM manipulation
- event handling
- animation handling
- state management
- performance-aware frontend work
- basic creative coding / 3D web graphics skills
This project was intentionally built as a single-file static artifact to make it easy to:
- review
- share
- run locally
- include in a portfolio
It is a strong example of combining interactive UI engineering with visual presentation in a compact frontend build.