Data-driven bar animation where the counters match each real rank swap.
Data-driven bar animation where the counters match each real rank swap.
No runs posted yet. Be the first: post yours and tag @wikiwayne.
BAR RACE: Ten Made-Up Cities Over Fifty Years
HOOK OBJECT: window.__race
Build "BAR RACE": an animated bar-chart race in pure SVG (no canvas, no libraries). Ten made-up cities race along horizontal bars as their populations grow from 1975 to 2025: bars lengthen, swap places with a smooth slide, and the leader changes. It is one simple motion with a lot of drama.
LOOK
- Style: clean modern data-journalism look. Background #101826, bars in ten different bright colors: #FF6B6B, #FFB84D, #FFE066, #7BD88F, #4ECDC4, #4DA3FF, #8C7BFF, #D67BFF, #FF7BB5, #A0AEC0. Text #E8EEF7. Each bar has rounded ends, the city name inside the left end of the bar (dark text, at least 18 px), and the value at the right end outside the bar (for example "4.79 M", at least 18 px).
- Ten bars, 48 px tall with 14 px gaps at 1280x720 (scale with the screen), stacked from the top; the ten bars together fill at least 70% of the screen height. A thin vertical axis line on the left edge of the bars, and a few faint vertical grid lines with value labels along the bottom that rescale as the longest bar grows.
- A big year label (for example "1975", 96 px, #FFFFFF at 25% opacity) sits at the bottom-right, a title "CITY POPULATION RACE" at the top-left, never over the bars.
- FIRST FRAME (t = 0, no input): the ten bars sorted from longest to shortest for the year 1975, the year label reading 1975, the bars filling at least 70% of the screen height.
MOTION / PLAY
- The data is exact. Populations in thousands, with 1975 value and yearly growth rate, for the year Y: value = start x (1 + rate) ^ (Y - 1975), calculated for fractional years too:
Marlowe 3200, 0.4%; Tindra 900, 3.4%; Ashby Port 2400, 1.0%; Kestrel Bay 1500, 2.2%; Velmora 600, 4.2%; Quillon 2900, 0.2%; Hartwell 1800, 1.6%; Orrin 1100, 2.8%; Bellhaven 2000, 0.8%; Dunmere 400, 5.0%.
- The race runs from 1975 to 2025 in 27 s of simulated time (50 years in 27 s). Bar length is proportional to the value on a scale whose maximum eases to 1.1 x the longest bar. Each bar's vertical slot follows its current rank (1 = top) and slides to a new slot over 0.4 s whenever the rank changes. The year label counts up whole years.
- At 2025 the chart holds for 1.5 s, then fades out over 0.5 s and the race starts again from 1975 (about 29 s for one loop).
- Controls: tap or drag along a timeline strip at the bottom to scrub to any year (the bars jump to the exact values); a play/pause button (at least 48 px) and the Space bar pause and resume; tap a bar to highlight it (the other bars dim to 40%) until you tap again. setView(year) sets the year directly.
- ATTRACT MODE: with no input, a hands-free demo starts on load and loops every 25–30 s, showing every main feature (the whole race, a highlight of Dunmere at 8 s and of Tindra at 20 s). Any input takes over; the demo resumes after 8 s with no input.
SOUND
- A soft ticking pulse once per year.
- A short "swoosh" each time two bars swap places (pitch rises when the swap is near the top).
- A bright chime when the leader changes.
- A low "thud" when the chart reaches 2025.
COUNTERS
stats() returns { fps, overtakes, leaderChanges, years }.
- overtakes: +1 exactly when one bar's value passes another bar's value and the two bars swap ranks (two bars swapping is one overtake). Never on load.
- leaderChanges: +1 exactly when the bar in first place changes.
- years: +1 exactly when the year label changes to a new whole year.
- On screen: the overtakes and leader-changes counts in a small row at the bottom-left, readable in a paused frame and never over the bars.
CHECKS for ?test=1
With ?test=1, run an accelerated self-test that measures real positions and real events (not self-set flags) and logs "TEST n PASS" or "TEST n FAIL: reason" to the console and to window.__testResults:
Each check starts from a fresh load; advance() steps in 1/60 s increments.
1. The page has no canvas element, has exactly 10 bars, they are sorted longest to shortest at 1975 (Marlowe first, Dunmere last), and they fill at least 70% of the screen height.
2. With setView(2025), the bar values equal the formula within 0.5% (Tindra about 4,789 and Dunmere about 4,587 thousand), and every bar's length divided by its value is the same within 1%.
3. Over advance(27), overtakes ends at exactly 37, which is the number of city pairs whose order at 1975 is the opposite of their order at 2025, and no pair ever swaps back.
4. After advance(27.1), leaderChanges is exactly 2, years is exactly 50, and the bar in first place at the end is Tindra.
5. At every frame of a 27 s run in which no slide is active (every bar has settled in its slot), the ten bars' vertical slots do not overlap (a gap of at least 4 px between neighbors); during a slide, two swapping bars may cross. The run has zero console errors.
KEEP IT SHORT
- Keep the whole file under about 1,500 lines (soft target) so you can write it in one pass and finish well inside 15 minutes.
- Save lines with helpers, loops and instancing, not by dropping features. Everything above must really work: no placeholders, no TODOs.
BUILD RULES (all required):
- Deliver ONE self-contained HTML file: inline CSS and JS, no build step, no local assets. Libraries only from a CDN. If you use Three.js, use exactly this import map: {"imports":{"three":"https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js","three/addons/":"https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/"}}
- It must open straight from disk in desktop Chrome and on an iPhone (Safari), fill the full screen, handle resize and touch, and stay smooth (target 60 fps).
- It must look stunning in the very FIRST frame: no black screen, no loading wait, no tiny subject. The main subject fills at least 50% of the screen height.
- SOUND (required): all sound is made in code with Web Audio (no audio files). Show a small "🔊 TAP FOR SOUND" chip; on the first tap create ONE AudioContext, route everything through a master gain of 0.6 into a DynamicsCompressor, and hide the chip. Also expose enableAudio() on the hook object named at the top.
- Expose the hook object named at the top with: setCameraOrbit(azimuthDeg, elevationDeg, distance) (or an equivalent camera setter), advance(seconds) that steps the simulation exactly that much for still captures, enableAudio(), and stats() returning {fps, ...the counters named above}. Use a fixed random seed of 360 so every run is the same.
- Every on-screen counter must count a real event you can see happen. No fake numbers.
- No text overlapping the subject; any label must be readable in a paused frame.
- No brand logos, no real people, no copyrighted characters, brand names or logos.
FAILURE MODES TO AVOID
- A blank page, or only the title on a blank page, because one script error stopped the scene.
- Bars that jump to new slots instead of sliding, or bars that are still overlapping after their slide has ended.
- Bar lengths that are not proportional to the values, or a scale that jumps instead of easing.
- Value labels or city names that are cut off, tiny, or drawn on top of other bars.
- Using a canvas, an image file or a library instead of plain SVG.
- A year label that skips years or runs at a different speed from the bars.
- Counters that tick on a timer instead of when two bars actually swap.
- Real city names, logos or real data: only the ten made-up cities above.
- The same variable declared twice, or methods called on objects that don't exist yet.
SELF-TEST LOOP
- If you can run code: build the file, open it, read the console, run ?test=1, and take screenshots at 3 s, 10 s and 30 s at 1280x720 and 390x844. Look at the screenshots and fix what looks wrong. Fix and retest until all 5 checks pass with zero console errors. Mark anything you could not run as UNMEASURED; never invent results.
- If you are chat-only: go through this prompt line by line, check your code against each line, and fix anything that would fail. Then write one corrected, complete file.
- Final answer: ONE complete HTML file in ONE code block, then the 5 checks marked PASS, FAIL or UNMEASURED. No snippets, no "rest unchanged".
Built one? Post it on X and tag @wikiwaynePost on X