Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Inspired by this, I stayed up all night building this!

https://jsbin.com/josuxarufu/1/edit?js,console,output

It tries to "evolve" the target image (right) by making random changes to the origin (left) -- output after 1 step is in center.

It's eventually supposed to be a genetic algorithm, but for now it just goes through it pixel by pixel, and if the pixel doesn't match the target, it inverts one of its neighbors. If that's beneficial (checking loss in a 5x5 rect centered on the test pixel), we keep the change. I get loss down to about 25% then it plateaus.

Feel free to fiddle, fork, etc! (I stayed up pretty late so the code is bad! Suggestions welcome!)




Another strat I thought about is to precompute all possible outputs for all possible inputs. This is feasible for small tiles (e.g. 5x5 grid has ~35 million permutations), maybe a sliding window could be used. I'm stuck on how to deal with tile overlap, and the fact that many outputs have more than one input -- you'd want to check all possible input tiles against all possible neighboring input tiles?


Wouldn't it be better to have the target image as grayscale or black/white instead of dithered?


Maybe! That's a good idea! I guess I'd get natural dithering as the result of running a loss function on small windows against a grayscale image. (Per-pixel loss would be very high though, I guess you'd want to take the average brightness for some chunk?) I'm not sure how dithering is supposed to work though, maybe there's some improvements there over just taking the average brightness?




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: