Evolving Images with Random‑Mutation Hill Climbing (www.4rknova.com)

🤖 AI Summary
A developer built an interactive browser demo that “paints” a target image using only Random‑Mutation Hill Climbing (the (1+1) evolutionary strategy) and the Canvas 2D API — no machine learning, no training. Starting from random translucent shapes, the algorithm keeps a single best candidate, applies a small random mutation, and replaces the best only when the mutation lowers image error. The result is a smooth, responsive evolution you can watch in real time: because only one candidate is evaluated per iteration, the method fits strict frame budgets and runs thousands of mutation attempts per second without freezing the UI. Technically, each solution’s DNA is an ordered array of shape objects (geometry, color, alpha, z‑index). Mutations include vertex nudges, radius/color/alpha tweaks, shape-type respawns, and z‑order swaps — the latter often produces sudden gains because translucency and draw order interact. Fitness is measured with mean squared error (MSE) on RGB pixels; to save work a sampled MSE is computed first and only promising mutants trigger a full-image MSE. Performance engineering (working vs best canvases, preallocated buffers, cached color strings, controlled performance.now calls, and a per-frame time budget) keeps rendering fast and responsive. The demo demonstrates that simple evolutionary search, when paired with careful sampling and runtime budgeting, can effectively approximate images in constrained, real‑time environments and is useful for creative coding and lightweight optimization tasks.
Loading comments...
loading comments...