GPU point rendering at scale, fixed-count shader iteration, an exact seeded generator, live uniforms and real pixel readback.
GPU point rendering at scale, fixed-count shader iteration, an exact seeded generator, live uniforms and real pixel readback.
No runs posted yet. Be the first: post yours and tag @wikiwayne.
ATTRACTOR OBSERVATORY: a Million-Point Strange Attractor Drawn by the GPU, with Live Parameter Morphs
HOOK OBJECT: window.__attr
Build "ATTRACTOR OBSERVATORY": a WebGL page (no libraries) that draws exactly 1,000,000 points of a strange attractor in one draw call. Every point is its own starting position that the vertex shader pushes through a sine/cosine map a fixed 16 times, so the picture is computed on the GPU and never on the CPU. Four sliders change the map live, four presets jump to known beautiful shapes, and the hands-free demo morphs from one shape to the next. It is fun to keep watching because the glowing dust keeps folding into new shapes while the point count never drops.
LOOK
- Style: dark observatory with glowing additive dust. Palette: background #05060A, dust ramp #2F6BFF (slow steps) to #B34DFF to #FF7A3D (fast steps), HUD text #BFD4FF, slider track #26304A, slider thumb #7FA8FF, active preset button outline #FFB347.
- The map (all numbers are world units): x' = sin(a y) - cos(b x) and y' = sin(c x) - cos(d y). Both |x'| and |y'| are always at most 2, so every point lies inside the world square x and y from -2 to 2. Documented parameter ranges: a, b, c and d each from -3.0 to 3.0 (slider step 0.05).
- Points: N = 1,000,000. Point i starts at (x0, y0) = ((r1 * 2 - 1) * 1.5, (r2 * 2 - 1) * 1.5), where r1 and r2 are the (2i)-th and (2i+1)-th numbers (counting from 0) of this generator seeded with 360: function mulberry32(a){return function(){a|=0;a=a+0x6D2B79F5|0;let t=Math.imul(a^a>>>15,1|a);t=t+Math.imul(t^t>>>7,61|t)^t;return((t^t>>>14)>>>0)/4294967296}}. The 2,000,000 starting numbers go into one static Float32Array and one buffer, once. The vertex shader applies the map exactly 16 times (a loop with a constant bound of 16, so it also compiles on phones), keeps the last step length s = |p16 - p15|, and outputs the final position p16. highp float precision everywhere.
- Drawing: one gl.drawArrays(gl.POINTS, 0, 1000000) per frame, gl_PointSize = 1.0 (canvas pixels), additive blending gl.blendFunc(gl.SRC_ALPHA, gl.ONE), fragment color = ramp(clamp(s / 3.0, 0, 1)) normalized so its largest channel is exactly 1.0, with alpha 0.18. The canvas is cleared to #05060A every frame. A pixel counts as LIT when its largest channel is at least 36 (one point alone gives about 46 or more; the background is about 10).
- View: the canvas backing size is the CSS size times min(devicePixelRatio, 2) (all numbers below are canvas pixels at devicePixelRatio 1). The view square has side Q = 0.95 * min(W, H), centered in the canvas; world (x, y) maps to canvas pixel (W/2 + x * (Q / 4) * zoom * cos(az), H/2 - y * (Q / 4) * zoom * cos(el)) with zoom = 4 / distance. The camera setter setCameraOrbit(azimuthDeg, elevationDeg, distance) sets az, el and distance (default 0, 0, 4.0; limits az and el from -80 to 80, distance from 2.5 to 8.0, values outside are clamped). Dragging right increases az by 0.25 degrees per CSS px of horizontal movement and dragging down increases el by 0.25 per px of vertical movement; the mouse wheel multiplies distance by exp(deltaY * 0.001).
- Layout: HUD text 14 px monospace (8.4 px per character, at most 20 characters per line) and the controls never touch the view square. In landscape (width >= height) the HUD sits in the left strip and the controls in the right strip, each at least 250 px wide at 1280x720. In portrait the HUD sits in the strip above the view square and the controls in the strip below it. HUD lines: "POINTS 1,000,000", "ITERATIONS 16", "PRESET 1" (or "PRESET -" while no preset matches), "a 2.70 b -2.60", "c -2.50 d -2.30", "MORPHS 0", "CHANGES 0 JUMPS 0". Controls: four range sliders (a, b, c, d, from -3 to 3, step 0.05, each with a letter label and a value readout) and four preset buttons 1 to 4 (each at least 44 x 44 CSS px), plus the "🔊 TAP FOR SOUND" chip, which sits inside the HUD strip (and counts as a HUD rectangle).
- Presets (a, b, c, d): 1 = (2.7, -2.6, -2.5, -2.3), 2 = (2.7, -2.8, -1.9, 2.4), 3 = (1.6, -2.1, -2.7, 1.9), 4 = (2.9, -1.7, -1.8, -2.1). Every straight-line blend between preset k and preset k+1 (and 4 back to 1) keeps a full chaotic image; no blend collapses to a few dots.
- FIRST FRAME (t = 0, no input): preset 1 drawn from all 1,000,000 points, camera (0, 0, 4.0), HUD "PRESET 1", MORPHS 0, CHANGES 0, JUMPS 0. At 1280x720 Q = 684, so the view square is x 298 to 982 and y 18 to 702, the dust fills all of it (a 684 x 684 px picture, 95% of the window height), and about 335,000 pixels are lit. On a phone in portrait (390x844) Q = 370.5 and the picture is about 372 x 372 px, 95% of the width but only 44% of the height: that is an accepted exception.
MOTION / PLAY
- Controls: slider input changes one parameter live (the preset indicator becomes "-" unless all four values equal a preset); keys 1 to 4 or the preset buttons jump to that preset at once; drag and wheel move the camera as above; Space does nothing.
- Preset test: params equal preset k when each of the four values is within 1e-9 of it.
- ATTRACT MODE: with no input, a hands-free loop of exactly 1680 frames (28.0 s at 60 frames per second) runs from load, in four legs of 420 frames (7.0 s): hold the current preset 90 frames (1.5 s), then blend linearly to the next preset over 330 frames (5.5 s), progress f = (frames into the blend) / 330, params = start + (end - start) * f, and exactly the end preset when the blend finishes. Legs: 1 to 2, 2 to 3, 3 to 4, 4 to 1. Sum: 4 x (1.5 + 5.5) = 28.0 s. At frame 1680 the last blend finishes (the morph counter counts it) and the loop restarts at frame 0 with preset 1. Any input (pointer, key, wheel, slider) takes over and the demo pauses where it is; after 8 s with no input the demo restarts from frame 0 (params snap to preset 1; this snap is not counted as a morph, jump or change). Hook calls are not user input.
- Time: advance(seconds) runs round(60 * seconds) steps of 1/60 s; the demo clock counts those frames. The 8 s idle timer counts the same 1/60 s steps as advance() (never wall-clock time). In ?test=1 the page uses devicePixelRatio 1 (the canvas-pixel checks assume it).
- The hook also exposes: setParams(a, b, c, d) (clamps each value into [-3, 3], applies them, returns the four clamped values; it counts as a parameter change the same way a slider does), attract(on), preset(i) (i from 1 to 4, the same as pressing key i), seedPoint(i) returning [x0, y0] of point i, cpuOrbit(x0, y0, n) returning [x, y] after n applications of the map in float64 with the current parameters, camera() returning {az, el, dist}, litPixels() (the number of LIT pixels in the whole canvas), litBox() returning {x, y, w, h} (tight box around all LIT pixels, w = max column - min column + 1, same for h), litCells(n) returning a flat array of n x n counts of LIT pixels, row-major with row 0 at the top, for the n x n equal cells of the view square, pixel(x, y) returning [r, g, b, a] of one canvas pixel (y from the top), and layout() returning {view: {x, y, w, h}, hud: [rects], controls: [rects]} in CSS px. litPixels, litBox, litCells and pixel first redraw the current state and read the framebuffer in the same task, so they work although the canvas is not preserved.
SOUND
- A preset jump -> a whoosh (a noise burst through a band-pass filter sweeping 400 Hz to 1600 Hz, 0.4 s, gain 0.05).
- A morph finishes -> a chime (sine 659 Hz and sine 988 Hz, 0.6 s decay, gain 0.05 each).
- A slider or setParams change -> a blip (sine, frequency 330 Hz + 550 Hz * (new value + 3) / 6, 0.08 s, gain 0.04).
- A quiet drone: two sines at 55 Hz and 55.6 Hz, gain 0.02 each, always on after the first tap.
- With no AudioContext (before the first tap, and in ?test=1) nothing is played, but the triggers are still counted.
COUNTERS
stats() returns { fps, points, iterations, drawCalls, preset, params, morphs, paramChanges, jumps, soundTriggers }.
- points: the count argument of the last gl.drawArrays call (1000000). iterations: the loop bound used by the shader (16). drawCalls: the number of gl.drawArrays calls made while drawing the last frame (1).
- preset: 1 to 4 for the preset the params equal right now, 0 when none matches. params: [a, b, c, d] right now.
- morphs: +1 each time an attract blend finishes. paramChanges: +1 for each slider input event or setParams call that changes at least one value after clamping. jumps: +1 for each press of key 1 to 4, each preset button press and each preset(i) call, even when that preset is already shown.
- soundTriggers: +1 for every whoosh, chime and blip, whether or not sound is on; so it always equals jumps + morphs + paramChanges.
- On screen: the HUD lines above, readable in a paused frame and never over the view square.
CHECKS for ?test=1
With ?test=1, run an accelerated self-test that measures real pixels 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. After attract(false) at t = 0, at 1280x720: stats() has points 1000000, iterations 16, drawCalls 1, preset 1, params [2.7, -2.6, -2.5, -2.3], morphs 0, paramChanges 0, jumps 0 and soundTriggers 0; seedPoint(0), seedPoint(1) and seedPoint(999999) equal (-0.0175713, -0.3419292), (-1.4837999, -1.1187213) and (-0.5285228, 0.7630283) (each within 1e-6); pixel(2, 2) is [5, 6, 10, 255] (each within 2); litBox() is x 298, y 18, w 684, h 684 (each within 3); litPixels() is between 325,000 and 345,000; layout().view is x 298, y 18, w 684, h 684 (each within 2) and no HUD or controls rectangle overlaps it. At 390x844: litBox().w and litBox().h are each between 368 and 374 (about 44% of 844, the accepted exception), litPixels() is between 114,000 and 121,500, and layout().view is about x 9.75, y 236.75, w 370.5, h 370.5 (each within 2) with no HUD or controls rectangle overlapping it.
2. After attract(false), with preset 1 active: cpuOrbit(0.1, 0.1, 0) is [0.1, 0.1]; cpuOrbit(0.1, 0.1, 1) is [-0.6996585, -1.2210704]; cpuOrbit(0.1, 0.1, 3) is [-1.3845493, -0.5702187]; cpuOrbit(0.1, 0.1, 16) is [0.5702073, -1.7300960]; cpuOrbit(-0.5, 0.8, 2) is [-0.2428285, -0.0467285]; cpuOrbit(-0.5, 0.8, 16) is [1.5625468, 0.5507996] (each within 1e-6). After setCameraOrbit(60, 0, 4.0): camera() is {az 60, el 0, dist 4} and litBox().w is between 339 and 345 and h between 681 and 687. After setCameraOrbit(0, 60, 4.0): litBox().h is between 339 and 345 and w between 681 and 687. After setCameraOrbit(0, 0, 4.0), a real pointer drag (pointerdown, pointermove, pointerup) of 100 px to the right then 40 px down changes camera() to az 25 and el 10 (each within 0.5); a wheel event with deltaY 400 changes dist to 4 * exp(0.4) = 5.967 (within 0.01); setCameraOrbit(500, -500, 20) gives az 80, el -80, dist 8.
3. The GPU image equals a float64 reference computed by the test itself from the same 1,000,000 seeded points, 16 iterations each, with the same pixel mapping (a point lights the pixel floor(px), floor(py); count distinct pixels per cell of the 16 x 16 cells of the view square): litCells(16) must match that reference in every cell within 10% of the reference count plus 30 pixels, and litPixels() within 3% of the reference total. Do this three times at 1280x720: at preset 1 (reference total about 335,125), after the key 3 press (preset 3 selected, reference total about 302,301, litPixels() between 293,000 and 311,500), and after a real slider input event that sets the first slider (a) to 2.0 (params [2.0, -2.6, -2.5, -2.3], preset 0, reference total about 319,138, litPixels() between 309,500 and 328,500).
4. After attract(false): setParams(9, -9, 0.5, -0.5) returns [3, -3, 0.5, -0.5] and stats().paramChanges is 1; the same call again returns the same values and paramChanges stays 1; a real keydown of "4" gives preset 4, params [2.9, -1.7, -1.8, -2.1] and jumps 1; keydown "1" gives preset 1 and jumps 2; keydown "9" changes nothing (jumps 2); a real slider input event setting the slider a to 1.25 gives params[0] 1.25, preset 0 and paramChanges 2; stats().morphs is 0 and soundTriggers is 4 (= jumps 2 + morphs 0 + paramChanges 2); then 600 frames later the params are still [1.25, -2.6, -2.5, -2.3] (the demo is off).
5. Fresh load with the demo running, advance() frame by frame to the times below (frames = 60 x t): at t = 1.0 params are [2.7, -2.6, -2.5, -2.3], preset 1 and litPixels() between 325,000 and 345,000; at t = 4.25 params are [2.7, -2.7, -2.2, 0.05] (each within 1e-6), preset 0 and morphs 0; at t = 4.5 litPixels() is between 148,000 and 189,000; at t = 7.2 morphs is 1, preset 2 and params [2.7, -2.8, -1.9, 2.4]; at t = 14.2 morphs 2 and preset 3; at t = 18.0 litPixels() is between 131,000 and 167,000; at t = 21.2 morphs 3 and preset 4; litPixels() read every 0.5 s from t = 0 to t = 28 stays between 120,000 and 345,000; at t = 28.2 morphs is 4, preset 1, params [2.7, -2.6, -2.5, -2.3], soundTriggers 4, paramChanges 0, jumps 0; then a real keydown "2" gives preset 2, jumps 1; 7.9 s later (no input) the params are still preset 2's values and 0.3 s after that they are preset 1's values again with morphs still 4; and 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
- Computing the attractor on the CPU every frame (the page crawls) or drawing fewer than 1,000,000 points, or drawing them in many draw calls instead of one.
- A shader loop with a non-constant bound or a different iteration count than 16, so it fails to compile on a phone or draws a different picture than the CPU reference.
- Seeds that are not the stated generator (seed 360, two numbers per point, range -1.5 to 1.5), so the picture and seedPoint() do not match the reference.
- Flat, washed-out dust: no additive blending, point size above 1, or an alpha that is not 0.18, so the lit-pixel counts and the density look are wrong.
- A view that is not the 0.95 * min(W, H) square, a picture that is tiny or off center, or a canvas that ignores resize or devicePixelRatio.
- A blend that collapses to a few dots or an empty frame, a morph that jumps instead of blending in 330 frames, or params that do not end exactly on the target preset.
- Live controls that do nothing: sliders that do not change the picture, preset keys that need a click first, parameters outside [-3, 3], or counters that miss a slider, key or setParams change.
- Text or buttons drawn over the picture, tap targets smaller than 44 px, or the HUD wider than its strip.
- A black first frame, a page that waits before drawing, or hooks (litCells, litPixels, pixel) that read a blank buffer because they did not redraw first.
- 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