In my previous post I wrote Python code that could generate a pleasing gradient palette from a photo. I decided to port that code to Rust to see what it would look like. The following is a Jupyter notebook of the Rust code to do the same thing. This uses evcxr to run Rust within a notebook. It works like magic, but sometimes has weirdness when using variables across cells.


With a naive performance test it takes about 4 seconds to run the Rust ACO algorithm while the previous PyPy version took 34 seconds. The ACO algorithm was well-suited to writing in a functional paradigm. I used a struct for the algorithm parameters with some reasonable defaults. There's some opportunity to make the data structures more efficient and apply parallel processing (perhaps with SIMD or on the GPU) in the calculations.