At this point, the guide transitions from a step by step tutorial to a high level overview of the source code demonstrating how the website was implemented. The demo portion of the website allows users to apply the k-means clustering algorithm to an image. The algorithm gives the resulting image a softened, painted look.
See the repositories Readme for instructions on building and running the project.
General Project Structure
There are a few new parameters in this .cargo/config file:
-s EXPORT_NAME='AsmjsModuleInitializer'- the variable name which contains the asm.js export
-s MODULARIZE=1- export a function which creates an asm.js module opposed to exporting the module directly
-s ALLOW_MEMORY_GROWTH=1- allow the heap size of the asm.js module to grow
We do something similar for the WebAssembly target, but we do not use the
-s MODULARIZE=1 flag.
K-means Clustering Algorithm
Painters provide an API for taking raw image data and painting it using the k-means algorithm. The raw image data is represented as a one dimensional
Vector (Rust) or
image_width * image_height * 4. The
4 represents the four channels of a pixel: red, blue, green, and alpha.