Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/jakeroggenbuck/colorgradient-rs
- Owner: JakeRoggenbuck
- License: mit
- Created: 2021-05-01T07:04:40.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-01-01T07:31:27.000Z (almost 2 years ago)
- Last Synced: 2023-03-03T22:23:25.620Z (over 1 year ago)
- Topics: color-scheme, rust, rust-lang
- Language: Rust
- Homepage:
- Size: 27.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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)# 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;
}
```