Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jakeroggenbuck/colorgradient-rs

Generate a gradient from selected colors
https://github.com/jakeroggenbuck/colorgradient-rs

color-scheme rust rust-lang

Last synced: 5 days ago
JSON representation

Generate a gradient from selected colors

Awesome Lists containing this project

README

        

# colorgradient-rs
![image](https://user-images.githubusercontent.com/35516367/116793337-1716c680-aa7b-11eb-9c1e-2cda170e2118.png)

- Python version [colorgradient](https://github.com/JakeRoggenbuck/colorgradient)
- Rust version [colorgradient-rs](https://github.com/JakeRoggenbuck/colorgradient-rs)
- Julia version [colorgradient-julia](https://github.com/JakeRoggenbuck/colorgradient-julia)
- C version [colorgradient-c](https://github.com/JakeRoggenbuck/colorgradient-c)
- Go version [colorgradient-go](https://github.com/JakeRoggenbuck/colorgradient-go)
- Clojure version [colorgradient-clj](https://github.com/JakeRoggenbuck/colorgradient-clj)

color grad

# Install
```
git clone https://github.com/JakeRoggenbuck/colorgradient-rs
cargo install --path colorgradient-rs
```

# Test
```
cargo test
```

# Code
```rs
fn calculate_gradient(num: i64, original_colors: Vec) -> Vec {
// Get the needed step value to fit the num of iterations in the original_colors length
let step: f32 = (original_colors.len() as f32 - 1.0) / num as f32;
let channels = get_channels(original_colors);
let mut colors = Vec::::new();

for i in 0..num {
// Use step to count up with index
let x: f32 = i as f32 * step;
let mut color = Vec::new();
// Get each channel as a reference, use it as the known x values
for channel in [&channels.red, &channels.green, &channels.blue].iter() {
// Add the y values found from the x value to the color
color.push(find_y(x as f32, channel).abs());
}
// Change the vector of colors to RGB structure, and add it to all the colors
colors.push(vec_to_rgb!(color));
}
return colors;
}
```