Show HN: I made a WebGL-based app that traces images using circles (phqb.github.io)
The most challenging part (to me) is to find a way to convert images to vector lines. I had tried Potrace, but its output is not suitable for my use case: too many small elements share the same border. Potrace's goal is to represent the original image faithfully using vector lines. But I want to trace the image edges.
After searching and trying some Potrace alternatives in vain, I finally found my keyword. Surprisingly (to me), it lies at the end of the wiki page of the very topic [2]. Then I found a paper [3] that has nice pseudocode and a C implementation. I rewrote the pseudocode in Rust because I wanted to experiment with rustwasm. Honestly, I didn't care much about the math behind it.
From then, I could continue to finish the app and show it to the world.
This app is also my chance to learn about rustwasm and WebGL.
FYI: this app is offline-only; your images never leave your browser
[0] https://www.youtube.com/watch?v=r6sGWTCMz2k
[1] https://www.youtube.com/watch?v=-qgreAUpPwM
24 comments
[ 3.1 ms ] story [ 72.0 ms ] threadPerhaps above "Choose a picture" you should add a title that says "Try it now with your picture".
I don't even have any on my new laptop, just some screenshots of Wordle.
This beautiful phrase will drastically reduce my documentation workload.
I like that you took the step of doing edge detection. For what it's worth opencv supports edge detection and has a web assembly implementation: https://docs.opencv.org/4.x/d4/da1/tutorial_js_setup.html
Quaternions have four components [0].
Has anyone discovered a kind of number that contains three components?
[0] https://en.wikipedia.org/wiki/Quaternion
It redraws images with shape primitives and allows verctorization with a cool art style.
Is there any way to save/load the Fourier coefficients?
Thanks so much for adding the sample pictures.
It was made in 1kb for the JS1K demo competition: https://js1k.com/2018-coins/demo/3124
Detailed source code: https://github.com/xem/epicycles/blob/gh-pages/index.html
Controls:
- Arrow keys: up / down to change the number of gears, left to toggle intermediate paths, right to clear the scene.
- Mouse: click to add points to the path