seancroach / hex_color Goto Github PK
View Code? Open in Web Editor NEWA Rust library for parsing, serializing, and operating on hex colors.
License: Apache License 2.0
A Rust library for parsing, serializing, and operating on hex colors.
License: Apache License 2.0
Title
Please fix github link on crates.io
Similar to the CSS rules for lighten, darken, brightness.
Because this is too annoying:
// Lighten 20%
const LIGHTEN_AMT: f32 = 1.2;
let (r, g, b, _a) = HexColor::from_u24(0x66bbff).split();
let (r, g, b) = (
(r as f32 * LIGHTEN_AMT).max(u8::MAX as f32) as u8,
(g as f32 * LIGHTEN_AMT).max(u8::MAX as f32) as u8,
(b as f32 * LIGHTEN_AMT).max(u8::MAX as f32) as u8,
);
HexColor::from_u24(
(0xff & r as u32) << 16
| (0xff & g as u32) << 8
| (0xff & b as u32),
)
Hey! I thought this was abandoned. Thanks for getting around to it all!
Currently println!("{}", my_color)
will print #RRGGBB
Currently println!("{:?}", my_color)
will print #RRGGBBAA
I'm not satisfied with how this works. For one, {:?}
is supposed to be a debug print. This is standard across Rust. If you rely on the current behavior, it would confuse a code reviewer what's actually going on here.
I was going to suggest next to set the default Display
to print the full color: #RRGGBBAA
And use #[derive(Debug)]
to handle the debug print, as one would expect.
To maintain functionality, we could add sugary functions for more readability/context:
color.rgb_str()
and color.rgba_str()
Lovely library! I just made a function that naively inverts colors and I'd like to add it as a method to the main struct
const fn invert_color(color: HexColor) -> HexColor {
let r = 0xFF - color.r;
let g = 0xFF - color.g;
let b = 0xFF - color.b;
HexColor::new(r, g, b)
}
Maybe later I can implement a gamma corrected invert function.
Do you think this is a good idea? If not, I don't mind if you close this.
Hi, thanks to the library! It helps get things done easily.
Currently alpha channel is not supported yet, is there any plan to work on it?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.