Crates.io | color-operators |
lib.rs | color-operators |
version | 0.0.3 |
source | src |
created_at | 2021-06-16 23:10:15.412751 |
updated_at | 2021-06-17 23:20:13.062826 |
description | Color data structures, converters, and arithmetic operators |
homepage | https://github.com/rust-utilities/color-operators |
repository | https://github.com/rust-utilities/color-operators |
max_upload_size | |
id | 411070 |
size | 157,424 |
Color data structures, converters, comparators, and arithmetic operators
This repository requires Rust language/compiler to build from source
As of last update to this ReadMe file, the recommended method of installing Rust is via the installer script...
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
This repository is a Rust library, define it as a dependency within a project Cargo.toml
file...
Cargo.toml
(snip)
[dependencies]
color-operators = "0.0.3"
Check Rust -- Doc -- Specifying Dependencies for details about defining dependencies.
Then include within a source file via use
statement...
src/main.rs
(snip)
extern crate color_operators;
use color_operators::hsl::HSL;
use color_operators::hsv::HSV;
use color_operators::rgb::RGB;
Create a project if one does not already exist...
cargo init hsl-to-rgb
cd hsl-to-rgb
Add this crate as a dependency...
Cargo.toml
(snip)
[dependencies]
color-operators = "0.0.3"
argparse = "0.2.2"
Note,
argparse
is optional and only included to ensure following example functions as shown
Write code that utilizes this crate...
src/main.rs
extern crate argparse;
use argparse::{ ArgumentParser, StoreOption };
extern crate json;
extern crate color_operators;
use color_operators::rgb::RGB;
use color_operators::hsl::HSL;
fn main() {
let mut red_argument: Option<u8> = None;
let mut green_argument: Option<u8> = None;
let mut blue_argument: Option<u8> = None;
{
let mut ap = ArgumentParser::new();
ap.set_description("Convert RGB to HSL representation");
ap.refer(&mut red_argument).add_option(
&["--red", "-r"],
StoreOption,
"Red component"
);
ap.refer(&mut green_argument).add_option(
&["--green", "-g"],
StoreOption,
"Green component"
);
ap.refer(&mut blue_argument).add_option(
&["--blue", "-b"],
StoreOption,
"Blue component"
);
ap.parse_args_or_exit();
}
let red = red_argument.unwrap_or_default();
let green = green_argument.unwrap_or_default();
let blue = blue_argument.unwrap_or_default();
let rgb = RGB::new(red, green, blue);
let hsl = HSL::from(rgb);
println!("{:?}", hsl);
}
Test conversion with various options...
cargo run -- -r 255
#> HSL { hue: 0.0, saturation: 1.0, lightness: 0.5 }
cargo run -- -g 255
#> HSL { hue: 120.0, saturation: 1.0, lightness: 0.5 }
cargo run -- -b 255
#> HSL { hue: 240.0, saturation: 1.0, lightness: 0.5 }
cargo run -- -r 42 -b 42
#> HSL { hue: 300.0, saturation: 1.0, lightness: 0.08235294117647059 }
This repository may not be feature complete and/or fully functional, Pull Requests that add features or fix bugs are certainly welcomed.
Warning color conversion is not guaranteed to be fully reversible! For example 25 + 25
may not result in 50
after conversions, where as 24 + 24
will usually equal 48
... This seems to often be because of binary and decimal conversions and arithmetic.
Examples may be found within the examples/
directory and run to test conversions and other features;
cargo run --example rgb-to-hsl -- -r 255
#> HSL { hue: 0.0, saturation: 1.0, lightness: 0.5 }
cargo run --example rgb-to-hsv -- -g 255
#> HSV { hue: 120.0, saturation: 1.0, value: 1.0 }
For regular operations this project depends;
hex
crate provides hexadecimal string to decimal parsing
json
crate allows for string serialization and de-serialization
Examples depend on;
argparse
carte provides command line argument parsing and type coercion
Lents depend on;
clippy
crate throws errors and warnings for common code-smells
Options for contributing to color-operators and rust-utilities
Start making a Fork of this repository to an account that you have write permissions for.
Add remote for fork URL. The URL syntax is git@github.com:<NAME>/<REPO>.git
...
cd ~/git/hub/rust-utilities/color-operators
git remote add fork git@github.com:<NAME>/color-operators.git
Commit your changes and push to your fork, eg. to fix an issue...
cd ~/git/hub/rust-utilities/color-operators
git commit -F- <<'EOF'
:bug: Fixes #42 Issue
**Edits**
- `<SCRIPT-NAME>` script, fixes some bug reported in issue
EOF
git push fork main
Note, the
-u
option may be used to setfork
as the default remote, eg.git push -u fork main
however, this will also default thefork
remote for pulling from too! Meaning that pulling updates fromorigin
must be done explicitly, eg.git pull origin main
Then on GitHub submit a Pull Request through the Web-UI, the URL syntax is https://github.com/<NAME>/<REPO>/pull/new/<BRANCH>
Note; to decrease the chances of your Pull Request needing modifications before being accepted, please check the dot-github repository for detailed contributing guidelines.
Tip check for TODO
lines for known arias that may cause issues, as well as portions of code that are excellent targets for new Pull Requests...
grep -C3 -ri 'todo' src/**/*.rs
Thanks for even considering it!
Via Liberapay you may on a repeating basis.
Regardless of if you're able to financially support projects such as color-operators that rust-utilities maintains, please consider sharing projects that are useful with others, because one of the goals of maintaining Open Source repositories is to provide value to the community.
Color data structures, converters, comparators, and arithmetic operators
Copyright (C) 2021 S0AndS0
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For further details review full length version of AGPL-3.0 License.